Module: Zuul::ActiveRecord::Permission::ClassMethods

Defined in:
lib/zuul/active_record/permission.rb

Class Method Summary collapse

Class Method Details

.add_associations(base) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/zuul/active_record/permission.rb', line 24

def self.add_associations(base)
  base.send :has_many, base.auth_scope.permission_role_plural_key, :class_name => base.auth_scope.permission_role_class_name, :dependent => :destroy
  base.send :has_many, base.auth_scope.role_plural_key, :class_name => base.auth_scope.role_class_name, :through => base.auth_scope.permission_role_plural_key

  base.send :has_many, base.auth_scope.permission_subject_plural_key, :class_name => base.auth_scope.permission_subject_class_name, :dependent => :destroy
  base.send :has_many, base.auth_scope.subject_plural_key, :class_name => base.auth_scope.subject_class_name, :through => base.auth_scope.permission_subject_plural_key
end

.add_validations(base) ⇒ Object



18
19
20
21
22
# File 'lib/zuul/active_record/permission.rb', line 18

def self.add_validations(base)
  base.send :validates_presence_of, :slug
  base.send :validates_uniqueness_of, :slug, :scope => [:context_id, :context_type], :case_sensitive => false
  base.send :validates_format_of, :slug, :with => /\A[a-z0-9_]+\Z/
end

.extended(base) ⇒ Object



11
12
13
14
15
16
# File 'lib/zuul/active_record/permission.rb', line 11

def self.extended(base)
  base.send :attr_accessible, :context, :context_id, :context_type, :slug if ::Zuul
.should_whitelist?
  add_validations base
  add_associations base
end