Class: Positioning::Mechanisms

Inherits:
Object
  • Object
show all
Defined in:
lib/positioning/mechanisms.rb

Instance Method Summary collapse

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_positionObject



16
17
18
19
20
# File 'lib/positioning/mechanisms.rb', line 16

def create_position
  solidify_position

  expand(positioning_scope, position..)
end

#destroy_positionObject



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

#priorObject



8
9
10
# File 'lib/positioning/mechanisms.rb', line 8

def prior
  positioning_scope.where("#{@column}": position - 1).first
end

#subsequentObject



12
13
14
# File 'lib/positioning/mechanisms.rb', line 12

def subsequent
  positioning_scope.where("#{@column}": position + 1).first
end

#update_positionObject



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..)
      expand(positioning_scope, position..)
    elsif position_was > position
      expand(positioning_scope, position..position_was)
    else
      contract(positioning_scope, position_was..position)
    end
  end
end