Sha256: 1668406fbe64cbc009f93a757cb4623e19e3267a6a42f72155ed6c70ef4c1869
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
module FlexibleFeeds module ActsAsParent extend ActiveSupport::Concern module ClassMethods def acts_as_parent(options = {}) cattr_accessor :permitted_children cattr_accessor :unpermitted_children self.permitted_children = options[:permitted_children] self.unpermitted_children = options[:unpermitted_children] def is_parental? true end send :include, InstanceMethods end end module InstanceMethods def is_parental? true end def children FlexibleFeeds::Event.where(parent: event).includes(:eventable) end def descendants FlexibleFeeds::Event.where(ancestor: event).includes(:eventable) end def parent_of(child) if can_accept_child?(child.eventable) ancestor = self.try(:ancestor) || self.event child.update_attributes(parent: self.event, ancestor: ancestor) child.increment_parent_counter end end private def can_accept_child?(child) if self.class.permitted_children.present? self.class.permitted_children.include?(child.class) elsif self.class.unpermitted_children.present? !self.class.unpermitted_children.include?(child.class) else child.try(:is_childish?) end end def initialize_event event || create_event end end end end ActiveRecord::Base.send :include, FlexibleFeeds::ActsAsParent
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
flexible_feeds-0.3.1 | lib/flexible_feeds/acts_as_parent.rb |
flexible_feeds-0.3.0 | lib/flexible_feeds/acts_as_parent.rb |