Module: Sequel::Plugins::Tree::ClassMethods
- Defined in:
- lib/sequel/plugins/tree.rb
Instance Attribute Summary collapse
-
#parent_column ⇒ Object
The symbol for the column containing the value pointing to the parent of the leaf.
-
#tree_order ⇒ Object
The column symbol or array of column symbols on which to order the tree.
Instance Method Summary collapse
-
#freeze ⇒ Object
Should freeze tree order if it is an array when freezing the model class.
-
#roots ⇒ Object
Returns list of all root nodes (those with no parent nodes).
-
#roots_dataset ⇒ Object
Returns the dataset for retrieval of all root nodes.
Instance Attribute Details
#parent_column ⇒ Object
The symbol for the column containing the value pointing to the parent of the leaf.
62 63 64 |
# File 'lib/sequel/plugins/tree.rb', line 62 def parent_column @parent_column end |
#tree_order ⇒ Object
The column symbol or array of column symbols on which to order the tree.
58 59 60 |
# File 'lib/sequel/plugins/tree.rb', line 58 def tree_order @tree_order end |
Instance Method Details
#freeze ⇒ Object
Should freeze tree order if it is an array when freezing the model class.
67 68 69 70 71 |
# File 'lib/sequel/plugins/tree.rb', line 67 def freeze @tree_order.freeze if @tree_order.is_a?(Array) super end |
#roots ⇒ Object
Returns list of all root nodes (those with no parent nodes).
TreeClass.roots # => [root1, root2]
76 77 78 |
# File 'lib/sequel/plugins/tree.rb', line 76 def roots roots_dataset.all end |
#roots_dataset ⇒ Object
Returns the dataset for retrieval of all root nodes
TreeClass.roots_dataset # => Sequel::Dataset instance
83 84 85 86 87 |
# File 'lib/sequel/plugins/tree.rb', line 83 def roots_dataset ds = where(Sequel.or(Array(parent_column).zip([]))) ds = ds.order(*tree_order) if tree_order ds end |