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

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Move) initialize(target, position, instance)

Returns a new instance of Move



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

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

Instance Attribute Details

- (Object) instance (readonly)

Returns the value of attribute instance



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

def instance
  @instance
end

- (Object) position (readonly)

Returns the value of attribute position



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

def position
  @position
end

- (Object) target (readonly)

Returns the value of attribute target



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

def target
  @target
end

Instance Method Details

- (Object) move



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/plugins/awesome_nested_set/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.where(where_statement(a, d)).update_all(
    conditions(a, b, c, d)
  )
end