Module: Rooftop::Nested
- Defined in:
- lib/rooftop/nested.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'lib/rooftop/nested.rb', line 4 def self.included(base) @nested_classes ||= [] @nested_classes << base unless @nested_classes.include?(base) end |
.nested_classes ⇒ Object
9 10 11 |
# File 'lib/rooftop/nested.rb', line 9 def self.nested_classes @nested_classes end |
Instance Method Details
#ancestors ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rooftop/nested.rb', line 17 def ancestors if respond_to?(:resource_links) resource_links.find_by(link_type: "#{Rooftop::ResourceLinks::CUSTOM_LINK_RELATION_BASE}/ancestors") else [] end end |
#children ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/rooftop/nested.rb', line 25 def children if respond_to?(:resource_links) resource_links.find_by(link_type: "#{Rooftop::ResourceLinks::CUSTOM_LINK_RELATION_BASE}/children") else [] end end |
#parent ⇒ Object
33 34 35 36 37 |
# File 'lib/rooftop/nested.rb', line 33 def parent if respond_to?(:resource_links) && resource_links ancestors.first end end |
#root ⇒ Object
13 14 15 |
# File 'lib/rooftop/nested.rb', line 13 def root ancestors.last || resource_links.find_by(link_type: 'self').first end |
#siblings ⇒ Object
39 40 41 |
# File 'lib/rooftop/nested.rb', line 39 def siblings self.class.find(parent.id).children.reject! {|c| c.id == self.id} end |