Module: Locomotive::Concerns::Page::Tree
- Extended by:
- ActiveSupport::Concern
- Included in:
- Page
- Defined in:
- app/models/locomotive/concerns/page/tree.rb
Defined Under Namespace
Modules: PatchedTreeMethods
Instance Method Summary collapse
-
#children_with_minimal_attributes(attrs = []) ⇒ Array
Returns the children of this node but with the minimal set of required attributes.
- #depth ⇒ Object
-
#siblings_and_self_with_scoping ⇒ Mongoid::Criteria
Returns this document’s siblings and itself, all scoped by the site.
-
#sort_children!(ids) ⇒ Object
Assigns the new position of each child of this node.
Instance Method Details
#children_with_minimal_attributes(attrs = []) ⇒ Array
Returns the children of this node but with the minimal set of required attributes
54 55 56 |
# File 'app/models/locomotive/concerns/page/tree.rb', line 54 def children_with_minimal_attributes(attrs = []) self.children.minimal_attributes(attrs) end |
#depth ⇒ Object
81 82 83 |
# File 'app/models/locomotive/concerns/page/tree.rb', line 81 def depth self.parent_ids.count end |
#siblings_and_self_with_scoping ⇒ Mongoid::Criteria
Returns this document’s siblings and itself, all scoped by the site
77 78 79 |
# File 'app/models/locomotive/concerns/page/tree.rb', line 77 def siblings_and_self_with_scoping base_class.where(parent_id: self.parent_id, site_id: self.site_id) end |
#sort_children!(ids) ⇒ Object
Assigns the new position of each child of this node.
62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/locomotive/concerns/page/tree.rb', line 62 def sort_children!(ids) position, cached_children = 0, self.children.to_a ids.each do |id| if child = cached_children.detect { |p| p._id == BSON::ObjectId.from_string(id) } child.position = position child.save position += 1 end end end |