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
21
22
# File 'lib/positioning/mechanisms.rb', line 16

def create_position
  lock_positioning_scope!

  solidify_position

  expand(positioning_scope, position..)
end

#destroy_positionObject



44
45
46
47
48
49
50
51
# File 'lib/positioning/mechanisms.rb', line 44

def destroy_position
  unless destroyed_via_positioning_scope?
    lock_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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/positioning/mechanisms.rb', line 24

def update_position
  return unless positioning_scope_changed? || position_changed?

  lock_positioning_scope!

  clear_position if positioning_scope_changed? && !position_changed?

  solidify_position
  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