module Rooftop::Nested
Public Class Methods
included(base)
click to toggle source
# File lib/rooftop/nested.rb, line 4 def self.included(base) @nested_classes ||= [] @nested_classes << base unless @nested_classes.include?(base) end
nested_classes()
click to toggle source
# File lib/rooftop/nested.rb, line 9 def self.nested_classes @nested_classes end
Public Instance Methods
ancestors()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/rooftop/nested.rb, line 33 def parent if respond_to?(:resource_links) && resource_links ancestors.first end end
root()
click to toggle source
# File lib/rooftop/nested.rb, line 13 def root ancestors.last || resource_links.find_by(link_type: 'self').first end
siblings()
click to toggle source
# File lib/rooftop/nested.rb, line 39 def siblings self.class.find(parent.id).children.reject! {|c| c.id == self.id} end