lib/rooftop/nested.rb in rooftop-0.0.6 vs lib/rooftop/nested.rb in rooftop-0.0.7.4

- old
+ new

@@ -1,8 +1,21 @@ module Rooftop module Nested + + def self.included(base) + @nested_classes ||= [] + @nested_classes << base unless @nested_classes.include?(base) + end + def self.nested_classes + @nested_classes + end + + def root + ancestors.last || resource_links.find_by(link_type: 'self').first + end + def ancestors if respond_to?(:resource_links) resource_links.find_by(link_type: "#{Rooftop::ResourceLinks::CUSTOM_LINK_RELATION_BASE}/ancestors") else [] @@ -16,11 +29,15 @@ [] end end def parent - if respond_to?(:resource_links) - resource_links.find_by(link_type: "up").first + if respond_to?(:resource_links) && resource_links + ancestors.first end + end + + def siblings + self.class.find(parent.id).children.reject! {|c| c.id == self.id} end end end \ No newline at end of file