Class: SimpleNestedSet::Move::ByAttributes

Inherits:
Object
  • Object
show all
Includes:
Protection
Defined in:
lib/simple_nested_set/move/by_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Protection

#impossible_move!, #inconsistent_move!, #protect_impossible_move!, #protect_inconsistent_move!

Constructor Details

#initialize(node, attributes) ⇒ ByAttributes

Returns a new instance of ByAttributes.



10
11
12
13
14
# File 'lib/simple_nested_set/move/by_attributes.rb', line 10

def initialize(node, attributes)
  @node, @attributes = node, attributes
  normalize_attributes!
  protect_inconsistent_move!
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/simple_nested_set/move/by_attributes.rb', line 6

def attributes
  @attributes
end

#nodeObject (readonly)

Returns the value of attribute node.



6
7
8
# File 'lib/simple_nested_set/move/by_attributes.rb', line 6

def node
  @node
end

Instance Method Details

#performObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simple_nested_set/move/by_attributes.rb', line 16

def perform
  move_by_parent_id if move_by_parent_id?

  if path && node.path_changed?
    node.move_to_path(path)
  elsif move_by_left_id?
    move_by_left_id
  elsif move_by_right_id?
    move_by_right_id
  end
end