Module: PrivatePerson::ActsAsPermissor::ClassMethods

Defined in:
lib/private_person/extensions/acts_as_permissor.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_permissor(params = {}) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/private_person/extensions/acts_as_permissor.rb', line 7

def acts_as_permissor(params = {})
  if params[:of].nil?
    raise 'Called acts_as_permissor, but without an :of parameter.'
  end
  class_attribute :of
  self.of = params[:of]
  class_name = params[:class_name] || params[:of].to_s.classify
  class_name.constantize.acts_as_permitted

  has_many :permissions_as_permissor, :as => :permissor, :class_name => 'PrivatePerson::Permission'
  has_many :permissibles, :through => :permissions, :as => :permissor, :class_name => class_name
  
  send :include, InstanceMethods
end