Module: Marley::Plugins::OrmMaterializedPath::InstanceMethods

Defined in:
lib/marley/plugins/orm_materialized_path.rb

Instance Method Summary collapse

Instance Method Details

#_pathObject



25
# File 'lib/marley/plugins/orm_materialized_path.rb', line 25

def _path;send(PATH_COL);end

#children_pathObject



29
# File 'lib/marley/plugins/orm_materialized_path.rb', line 29

def children_path;("#{_path}#{id}#{SEP}");end

#children_path_arrObject



30
# File 'lib/marley/plugins/orm_materialized_path.rb', line 30

def children_path_arr; children_path.split(SEP).map &:to_i; end

#depthObject



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_idObject



28
# File 'lib/marley/plugins/orm_materialized_path.rb', line 28

def parent_id; path_arr[-1]; end

#path_arrObject



26
# File 'lib/marley/plugins/orm_materialized_path.rb', line 26

def path_arr; _path.to_s.split(SEP).map &:to_i; end

#rest_colsObject



33
# File 'lib/marley/plugins/orm_materialized_path.rb', line 33

def rest_cols;super - [PATH_COL];end

#root_idObject



27
# File 'lib/marley/plugins/orm_materialized_path.rb', line 27

def root_id; path_arr[0]; end

#treeObject



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_dsObject



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_treeObject



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