Sha256: 62371f85540352b0d7880ab9d432f527d17712edd49d0a53e346933e87c1a614

Contents?: true

Size: 1.37 KB

Versions: 16

Compression:

Stored size: 1.37 KB

Contents

module GroupedPage

  def self.included(base)
    base.class_eval {
      has_groups
      has_one :homegroup, :foreign_key => 'homepage_id', :class_name => 'Group'
      include InstanceMethods
      alias_method_chain :permitted_group_ids, :inheritance
      alias_method_chain :cache?, :restrictions
    }
  end
  
  module InstanceMethods
    
    attr_reader :inherited_groups
    def inherited_groups
      @inherited_groups ||= self.parent ? Group.attached_to(self.ancestors) : []
    end
    
    # If a grandparent page is associated with a supergroup page
    # then all of the descendant pages are bound to all of the descendant groups.
    def inherited_group_ids
      self.ancestors.map(&:group_ids).flatten.uniq
    end

    def permitted_group_ids_with_inheritance
      (permitted_group_ids_without_inheritance + inherited_group_ids).flatten.uniq
    end

    # this is regrettably expensive and I plan to replace it with a 
    # private? method that would be cascaded on page update
    #
    def restricted?
      self.permitted_groups.any?
    end
    
    def cache_with_restrictions?
      cache_without_restrictions? && !restricted?
    end

    def has_inherited_group?(group)
      return self.inherited_groups.include?(group)
    end
    
    def group_is_inherited?(group)
      return self.has_inherited_group?(group) && !self.has_group?(group)
    end
    
  end

end


Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
radiant-reader-extension-3.0.32 lib/grouped_page.rb
radiant-reader-extension-3.0.31 lib/grouped_page.rb
radiant-reader-extension-3.0.30 lib/grouped_page.rb
radiant-reader-extension-3.0.29 lib/grouped_page.rb
radiant-reader-extension-3.0.28 lib/grouped_page.rb
radiant-reader-extension-3.0.27 lib/grouped_page.rb
radiant-reader-extension-3.0.26 lib/grouped_page.rb
radiant-reader-extension-3.0.25 lib/grouped_page.rb
radiant-reader-extension-3.0.24 lib/grouped_page.rb
radiant-reader-extension-3.0.23 lib/grouped_page.rb
radiant-reader-extension-3.0.20 lib/grouped_page.rb
radiant-reader-extension-3.0.19 lib/grouped_page.rb
radiant-reader-extension-3.0.18 lib/grouped_page.rb
radiant-reader-extension-3.0.17 lib/grouped_page.rb
radiant-reader-extension-3.0.16 lib/grouped_page.rb
radiant-reader-extension-3.0.15 lib/grouped_page.rb