DataMapper::Is::NestedSet::ClassMethods

Attributes

nested_set_parent[R]
nested_set_scope[R]

Public Instance Methods

adjust_gap!(scoped_set,at,adjustment) click to toggle source
# 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() click to toggle source
# 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) click to toggle source

rebuilds the nested set using parent/child relationships and a chosen order

# 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() click to toggle source

rebuilds the parent/child relationships (parent_id) from nested set (left/right values)

# 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() click to toggle source

get the root of the tree. if sets are scoped, this will return false

# 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() click to toggle source

not implemented

# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.