Class: SimpleNestedSet::Move::ByAttributes
- Inherits:
-
Object
- Object
- SimpleNestedSet::Move::ByAttributes
- Includes:
- Protection
- Defined in:
- lib/simple_nested_set/move/by_attributes.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(node, attributes) ⇒ ByAttributes
constructor
A new instance of ByAttributes.
- #perform ⇒ Object
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.
19 20 21 22 23 |
# File 'lib/simple_nested_set/move/by_attributes.rb', line 19 def initialize(node, attributes) @node, @attributes = node, attributes normalize_attributes! protect_inconsistent_move! end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
14 15 16 |
# File 'lib/simple_nested_set/move/by_attributes.rb', line 14 def attributes @attributes end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
14 15 16 |
# File 'lib/simple_nested_set/move/by_attributes.rb', line 14 def node @node end |
Class Method Details
.attribute_reader(*names) ⇒ Object
5 6 7 8 9 |
# File 'lib/simple_nested_set/move/by_attributes.rb', line 5 def attribute_reader(*names) names.each do |name| define_method(name) { attributes[name].blank? ? nil : attributes[name].to_i } end end |
Instance Method Details
#perform ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_nested_set/move/by_attributes.rb', line 25 def perform if left_id && left_id != node.id node.move_to_right_of(left_id) elsif right_id && right_id != node.id node.move_to_left_of(right_id) elsif parent_id != node.parent_id node.move_to_child_of(parent_id) end end |