Module: Marley::Plugins::OrmMaterializedPath::InstanceMethods
- Defined in:
- lib/marley/plugins/orm_materialized_path.rb
Instance Method Summary collapse
- #_path ⇒ Object
- #children_path ⇒ Object
- #children_path_arr ⇒ Object
- #depth ⇒ Object
- #new_child(vals = {}) ⇒ Object
- #parent_id ⇒ Object
- #path_arr ⇒ Object
- #rest_cols ⇒ Object
- #root_id ⇒ Object
- #tree ⇒ Object
- #tree_ds ⇒ Object
- #values_tree ⇒ Object
Instance Method Details
#_path ⇒ Object
25 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 25 def _path;send(PATH_COL);end |
#children_path ⇒ Object
29 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 29 def children_path;("#{_path}#{id}#{SEP}");end |
#children_path_arr ⇒ Object
30 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 30 def children_path_arr; children_path.split(SEP).map &:to_i; end |
#depth ⇒ Object
32 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 32 def depth; path_arr.length; end |
#new_child(vals = {}) ⇒ Object
31 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 31 def new_child(vals={}); self.class.new({PATH_COL => children_path}.update(vals)); end |
#parent_id ⇒ Object
28 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 28 def parent_id; path_arr[-1]; end |
#path_arr ⇒ Object
26 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 26 def path_arr; _path.to_s.split(SEP).map &:to_i; end |
#rest_cols ⇒ Object
33 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 33 def rest_cols;super - [PATH_COL];end |
#root_id ⇒ Object
27 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 27 def root_id; path_arr[0]; end |
#tree ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 35 def tree res=[block_given? ? (yield self) : [self,[]]] tree_ds.all.sort {|x,y| x.children_path_arr <=> y.children_path_arr}.each do |node| (1..(node.path_arr.length*2)).inject(res) {|arr,i| arr[-1]} << (block_given? ? (yield node) : [node,[]]) end res[0] end |
#tree_ds ⇒ Object
24 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 24 def tree_ds; self.class.list_dataset.filter(PATH_COL.like("#{children_path}%")); end |
#values_tree ⇒ Object
42 43 44 45 46 |
# File 'lib/marley/plugins/orm_materialized_path.rb', line 42 def values_tree tree do |n| n.rest_cols.map{|c| n.send(c)} << [] end end |