Class: Gitlab::RelativePositioning::Mover
- Inherits:
-
Object
- Object
- Gitlab::RelativePositioning::Mover
- Defined in:
- lib/gitlab/relative_positioning/mover.rb
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#start_position ⇒ Object
readonly
Returns the value of attribute start_position.
Instance Method Summary collapse
- #context(object, ignoring: nil) ⇒ Object
-
#initialize(start, range) ⇒ Mover
constructor
A new instance of Mover.
- #move(object, first, last) ⇒ Object
- #move_to_end(object) ⇒ Object
- #move_to_start(object) ⇒ Object
Constructor Details
#initialize(start, range) ⇒ Mover
Returns a new instance of Mover.
8 9 10 11 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 8 def initialize(start, range) @range = range @start_position = start end |
Instance Attribute Details
#range ⇒ Object (readonly)
Returns the value of attribute range.
6 7 8 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 6 def range @range end |
#start_position ⇒ Object (readonly)
Returns the value of attribute start_position.
6 7 8 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 6 def start_position @start_position end |
Instance Method Details
#context(object, ignoring: nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 48 def context(object, ignoring: nil) return unless object ItemContext.new(object, range, ignoring: ignoring) end |
#move(object, first, last) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 27 def move(object, first, last) raise ArgumentError, 'object is required' unless object lhs = context(first, ignoring: object) rhs = context(last, ignoring: object) focus = context(object) range = RelativePositioning.range(lhs, rhs) if range.cover?(focus) # Moving a object already within a range is a no-op elsif range.open_on_left? move_to_range_start(focus, range.rhs.relative_position) elsif range.open_on_right? move_to_range_end(focus, range.lhs.relative_position) else pos_left, pos_right = create_space_between(range) desired_position = position_between(pos_left, pos_right) focus.place_at_position(desired_position, range.lhs) end end |
#move_to_end(object) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 13 def move_to_end(object) focus = context(object, ignoring: object) max_pos = focus.max_relative_position move_to_range_end(focus, max_pos) end |
#move_to_start(object) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/gitlab/relative_positioning/mover.rb', line 20 def move_to_start(object) focus = context(object, ignoring: object) min_pos = focus.min_relative_position move_to_range_start(focus, min_pos) end |