Module: Locomotive::Extensions::Page::Tree
- Extended by:
- ActiveSupport::Concern
- Included in:
- Page
- Defined in:
- app/models/locomotive/extensions/page/tree.rb
Defined Under Namespace
Modules: ClassMethods, 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
103 104 105 |
# File 'app/models/locomotive/extensions/page/tree.rb', line 103 def children_with_minimal_attributes(attrs = []) self.children.minimal_attributes(attrs) end |
#depth ⇒ Object
128 129 130 |
# File 'app/models/locomotive/extensions/page/tree.rb', line 128 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
124 125 126 |
# File 'app/models/locomotive/extensions/page/tree.rb', line 124 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.
111 112 113 114 115 116 117 118 |
# File 'app/models/locomotive/extensions/page/tree.rb', line 111 def sort_children!(ids) cached_children = self.children.to_a ids.each_with_index do |id, position| child = cached_children.detect { |p| p._id == Moped::BSON::ObjectId(id) } child.position = position child.save end end |