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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parent_columnObject

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



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

def parent_column
  @parent_column
end

#tree_orderObject

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



47
48
49
# File 'lib/sequel/plugins/tree.rb', line 47

def tree_order
  @tree_order
end

Instance Method Details

#inherited(subclass) ⇒ Object

Copy the parent_column and order_column to the subclass.



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

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

#rootsObject

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

TreeClass.roots # => [root1, root2]


63
64
65
# File 'lib/sequel/plugins/tree.rb', line 63

def roots
  roots_dataset.all
end

#roots_datasetObject

Returns the dataset for retrieval of all root nodes

TreeClass.roots_dataset => Sequel#Dataset


70
71
72
73
74
# File 'lib/sequel/plugins/tree.rb', line 70

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