Welcome to mirror list, hosted at ThFree Co, Russian Federation.

relative_positioning.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c2a73b7cfe5db71701ade757f421fefd159497f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Gitlab
  module RelativePositioning
    STEPS = 10
    IDEAL_DISTANCE = 2**(STEPS - 1) + 1

    MIN_POSITION = Gitlab::Database::MIN_INT_VALUE
    START_POSITION = 0
    MAX_POSITION = Gitlab::Database::MAX_INT_VALUE

    MAX_GAP = IDEAL_DISTANCE * 2
    MIN_GAP = 2

    NoSpaceLeft = Class.new(StandardError)
    InvalidPosition = Class.new(StandardError)
    IllegalRange = Class.new(ArgumentError)
    IssuePositioningDisabled = Class.new(StandardError)

    def self.range(lhs, rhs)
      if lhs && rhs
        ClosedRange.new(lhs, rhs)
      elsif lhs
        StartingFrom.new(lhs)
      elsif rhs
        EndingAt.new(rhs)
      else
        raise IllegalRange, 'One of rhs or lhs must be provided' unless lhs && rhs
      end
    end
  end
end