Module: MongoidSortableTree::Tree::ClassMethods
- Defined in:
- lib/mongoid_sortable_tree.rb
Overview
This module implements class methods that will be available on the document that includes MongoidSortableTree::Tree
Instance Method Summary collapse
- #build_materialized_path(tailored_hierarchy_data: [], from_root: false, category_hierarchy: nil, klass: nil) ⇒ Object
- #build_tree_from_node(node, options = {}) ⇒ Object
- #build_tree_from_root(options = {}) ⇒ Object
Instance Method Details
#build_materialized_path(tailored_hierarchy_data: [], from_root: false, category_hierarchy: nil, klass: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongoid_sortable_tree.rb', line 21 def build_materialized_path(tailored_hierarchy_data: [], from_root: false, category_hierarchy: nil, klass: nil) target = from_root ? (klass.nil? ? self.roots : klass.classify.constantize.roots) : category_hierarchy.children target.each do |data| custom_display_data = { :id => data.id.to_s, :text => data.text, :icon => data.icon, :li_attr => data.li_attr, :a_attr => data.a_attr, :klass => klass, :children => build_materialized_path(category_hierarchy: data, klass: klass) } tailored_hierarchy_data << custom_display_data end tailored_hierarchy_data end |
#build_tree_from_node(node, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mongoid_sortable_tree.rb', line 42 def build_tree_from_node(node,={}) return_array = [] custom_display_data = { :id => node.id.to_s, :text => node.text, :icon => node.icon, :li_attr => node.li_attr, :a_attr => node.a_attr, :klass => [:klass], :children => build_materialized_path(category_hierarchy: node, klass: [:klass]) } return_array << custom_display_data end |
#build_tree_from_root(options = {}) ⇒ Object
38 39 40 |
# File 'lib/mongoid_sortable_tree.rb', line 38 def build_tree_from_root(={}) build_materialized_path(from_root: true, klass: [:klass]) end |