Class: Content
- Inherits:
-
Object
- Object
- Content
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/content.rb
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#ancestry ⇒ Object
embeds_one :constraint # the constraints of what fields are required, what child objects can be defined and how many, etc.
- #child_order=(order) ⇒ Object
- #to_param ⇒ Object
Class Method Details
.find_by_ancestry(ancestry = nil, id) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'app/models/content.rb', line 29 def self.find_by_ancestry(ancestry = nil, id) return self.find(id) unless ancestry parent = Content.find(ancestry.shift) while(parent_slug = ancestry.shift and parent_slug != id) do parent = parent.child_contents.find(parent_slug) end if parent parent.child_contents.find(id) end |
Instance Method Details
#ancestry ⇒ Object
embeds_one :constraint # the constraints of what fields are required, what child objects can be defined and how many, etc.
25 26 27 |
# File 'app/models/content.rb', line 25 def ancestry parent_content ? parent_content.ancestry << id : [id] end |
#child_order=(order) ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/content.rb', line 38 def child_order=(order) return unless order order = order.split(',') order.each {|e| e.strip!} self.child_contents = self.child_contents.sort_by {|kid| order.find_index(kid.id) } end |
#to_param ⇒ Object
45 46 47 |
# File 'app/models/content.rb', line 45 def to_param parent_content ? parent_content.to_param + '/' + id : id end |