Class: Positioning::Mechanisms
- Inherits:
-
Object
- Object
- Positioning::Mechanisms
- Defined in:
- lib/positioning/mechanisms.rb
Instance Method Summary collapse
- #create_position ⇒ Object
- #destroy_position ⇒ Object
-
#initialize(positioned, column) ⇒ Mechanisms
constructor
A new instance of Mechanisms.
- #prior ⇒ Object
- #subsequent ⇒ Object
- #update_position ⇒ Object
Constructor Details
#initialize(positioned, column) ⇒ Mechanisms
Returns a new instance of Mechanisms.
3 4 5 6 |
# File 'lib/positioning/mechanisms.rb', line 3 def initialize(positioned, column) @positioned = positioned @column = column.to_sym end |
Instance Method Details
#create_position ⇒ Object
16 17 18 19 20 |
# File 'lib/positioning/mechanisms.rb', line 16 def create_position solidify_position (positioning_scope, position..) end |
#destroy_position ⇒ Object
41 42 43 44 45 46 |
# File 'lib/positioning/mechanisms.rb', line 41 def destroy_position unless destroyed_via_positioning_scope? move_out_of_the_way contract(positioning_scope, (position_was + 1)..) end end |
#prior ⇒ Object
8 9 10 |
# File 'lib/positioning/mechanisms.rb', line 8 def prior positioning_scope.where("#{@column}": position - 1).first end |
#subsequent ⇒ Object
12 13 14 |
# File 'lib/positioning/mechanisms.rb', line 12 def subsequent positioning_scope.where("#{@column}": position + 1).first end |
#update_position ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/positioning/mechanisms.rb', line 22 def update_position clear_position if positioning_scope_changed? && !position_changed? solidify_position if positioning_scope_changed? || position_changed? move_out_of_the_way if positioning_scope_changed? contract(positioning_scope_was, position_was..) (positioning_scope, position..) elsif position_was > position (positioning_scope, position..position_was) else contract(positioning_scope, position_was..position) end end end |