Module: Zuul::ActiveRecord::Role::ClassMethods

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

Class Method Summary collapse

Class Method Details

.add_associations(base) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/zuul/active_record/role.rb', line 27

def self.add_associations(base)
  base.send :has_many, base.auth_scope.role_subject_plural_key, :class_name => base.auth_scope.role_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.role_subject_plural_key
  if base.auth_scope.config.with_permissions
    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.permission_plural_key, :class_name => base.auth_scope.permission_class_name, :through => base.auth_scope.permission_role_plural_key
  end
end

.add_validations(base) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/zuul/active_record/role.rb', line 19

def self.add_validations(base)
  base.send :validates_presence_of, :level, :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/
  base.send :validates_uniqueness_of, :level, :scope => [:context_id, :context_type]
  base.send :validates_numericality_of, :level, :only_integer => true
end

.extended(base) ⇒ Object



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

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