Module: Sequel::Plugins::Tree::ClassMethods

Defined in:
lib/sequel/plugins/tree.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) parent_column

The symbol for the column containing the value pointing to the parent of the leaf.



56
57
58
# File 'lib/sequel/plugins/tree.rb', line 56

def parent_column
  @parent_column
end

- (Object) tree_order

The column symbol or array of column symbols on which to order the tree.



52
53
54
# File 'lib/sequel/plugins/tree.rb', line 52

def tree_order
  @tree_order
end

Instance Method Details

- (Object) inherited(subclass)

Copy the parent_column and order_column to the subclass.



59
60
61
62
63
# File 'lib/sequel/plugins/tree.rb', line 59

def inherited(subclass)
  super
  subclass.parent_column = parent_column
  subclass.tree_order = tree_order 
end

- (Object) roots

Returns list of all root nodes (those with no parent nodes).

TreeClass.roots # => [root1, root2]


68
69
70
# File 'lib/sequel/plugins/tree.rb', line 68

def roots
  roots_dataset.all
end

- (Object) roots_dataset

Returns the dataset for retrieval of all root nodes

TreeClass.roots_dataset => Sequel#Dataset


75
76
77
78
79
# File 'lib/sequel/plugins/tree.rb', line 75

def roots_dataset
  ds = filter(parent_column => nil)
  ds = ds.order(*tree_order) if tree_order
  ds
end