Module: Inkwell::ActsAsInkwellCommunity::Config

Defined in:
lib/acts_as_inkwell_community/base.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_inkwell_communityObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/acts_as_inkwell_community/base.rb', line 12

def acts_as_inkwell_community
  validates :owner_id, :presence => true

  if ::Inkwell::Engine::config.respond_to?('community_table')
    has_many :communities_users, :class_name => 'Inkwell::CommunityUser'
    has_many :users, -> { where "inkwell_community_users.active" => true}, :through => :communities_users, :class_name => ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    has_many :admins, -> { where "inkwell_community_users.is_admin" => true, "inkwell_community_users.active" => true}, :through => :communities_users, :class_name => ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    has_many :writers, -> { where "inkwell_community_users.user_access" => ::Inkwell::Constants::CommunityAccessLevels::WRITE, "inkwell_community_users.active" => true}, :through => :communities_users, :class_name => ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    has_many :muted_users, -> { where "inkwell_community_users.muted" => true, "inkwell_community_users.active" => true}, :through => :communities_users, :class_name => ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    has_many :banned_users, -> { where "inkwell_community_users.banned" => true}, :through => :communities_users, :class_name => ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    has_many :asked_invitation_users, -> { where "inkwell_community_users.asked_invitation" => true}, :through => :communities_users, :class_name => ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    has_many :blog_items, -> { where :owner_type => ::Inkwell::Constants::OwnerTypes::COMMUNITY}, :class_name => 'Inkwell::BlogItem', :foreign_key => :owner_id
    has_many ::Inkwell::Engine::config.post_table, -> { where "inkwell_blog_items.item_type" => ::Inkwell::Constants::ItemTypes::POST}, :class_name => ::Inkwell::Engine::config.post_table.to_s.singularize.capitalize, :through => :blog_items
  end

  after_create :processing_a_community
  before_destroy :destroy_community_processing
  include ::Inkwell::ActsAsInkwellCommunity::InstanceMethods
end