Class: CollectiveIdea::Acts::NestedSet::Move

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_nested_set/move.rb

Defined Under Namespace

Classes: ImpossibleMove

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, position, instance) ⇒ Move

Returns a new instance of Move.



7
8
9
10
11
# File 'lib/awesome_nested_set/move.rb', line 7

def initialize(target, position, instance)
  @target = target
  @position = position
  @instance = instance
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



5
6
7
# File 'lib/awesome_nested_set/move.rb', line 5

def instance
  @instance
end

#positionObject (readonly)

Returns the value of attribute position.



5
6
7
# File 'lib/awesome_nested_set/move.rb', line 5

def position
  @position
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/awesome_nested_set/move.rb', line 5

def target
  @target
end

Instance Method Details

#moveObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/awesome_nested_set/move.rb', line 13

def move
  prevent_impossible_move

  bound, other_bound = get_boundaries

  # there would be no change
  return if bound == right || bound == left

  # we have defined the boundaries of two non-overlapping intervals,
  # so sorting puts both the intervals and their boundaries in order
  a, b, c, d = [left, right, bound, other_bound].sort

  lock_nodes_between! a, d

  nested_set_scope_without_default_scope.where(where_statement(a, d)).update_all(
    conditions(a, b, c, d)
  )
end