Module: DataMapper::Is::NestedSet::ClassMethods
- Defined in:
- lib/dm-is-nested_set/is/nested_set.rb
Instance Attribute Summary collapse
-
#nested_set_parent ⇒ Object
readonly
Returns the value of attribute nested_set_parent.
-
#nested_set_scope ⇒ Object
readonly
Returns the value of attribute nested_set_scope.
Instance Method Summary collapse
- #adjust_gap!(scoped_set, at, adjustment) ⇒ Object
- #leaves ⇒ Object
-
#rebuild_set_from_tree(order = nil) ⇒ Object
rebuilds the nested set using parent/child relationships and a chosen order.
-
#rebuild_tree_from_set ⇒ Object
rebuilds the parent/child relationships (parent_id) from nested set (left/right values).
-
#root ⇒ Object
get the root of the tree.
-
#roots ⇒ Object
not implemented.
Instance Attribute Details
#nested_set_parent ⇒ Object (readonly)
Returns the value of attribute nested_set_parent.
60 61 62 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 60 def nested_set_parent @nested_set_parent end |
#nested_set_scope ⇒ Object (readonly)
Returns the value of attribute nested_set_scope.
60 61 62 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 60 def nested_set_scope @nested_set_scope end |
Instance Method Details
#adjust_gap!(scoped_set, at, adjustment) ⇒ Object
62 63 64 65 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 62 def adjust_gap!(scoped_set,at,adjustment) scoped_set.all(:rgt.gt => at).adjust!({ :rgt => adjustment }, true) scoped_set.all(:lft.gt => at).adjust!({ :lft => adjustment }, true) end |
#leaves ⇒ Object
90 91 92 93 94 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 90 def leaves # TODO scoping, how should it act? # TODO supply filtering-option? all(:conditions => [ 'rgt = lft + ?', 1 ], :order => [ :lft ]) end |
#rebuild_set_from_tree(order = nil) ⇒ Object
rebuilds the nested set using parent/child relationships and a chosen order
109 110 111 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 109 def rebuild_set_from_tree(order = nil) # TODO pending end |
#rebuild_tree_from_set ⇒ Object
rebuilds the parent/child relationships (parent_id) from nested set (left/right values)
99 100 101 102 103 104 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 99 def rebuild_tree_from_set all.each do |node| node.parent = node.ancestor node.save end end |
#root ⇒ Object
get the root of the tree. if sets are scoped, this will return false
70 71 72 73 74 75 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 70 def root # TODO scoping # what should this return if there is a scope? always false, or node if there is only one? args = Hash[ nested_set_parent.zip([]) ] roots.length > 1 ? false : first(args) end |
#roots ⇒ Object
not implemented
80 81 82 83 84 85 |
# File 'lib/dm-is-nested_set/is/nested_set.rb', line 80 def roots # TODO scoping # TODO supply filtering-option? args = Hash[ nested_set_parent.zip([]) ] all(args) end |