Module: Zuul::ActiveRecord::PermissionSubject::ClassMethods

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

Class Method Summary collapse

Class Method Details

.add_associations(base) ⇒ Object



23
24
25
26
# File 'lib/zuul/active_record/permission_subject.rb', line 23

def self.add_associations(base)
  base.send :belongs_to, base.auth_scope.permission_singular_key, :class_name => base.auth_scope.permission_class_name
  base.send :belongs_to, base.auth_scope.subject_singular_key, :class_name => base.auth_scope.subject_class_name
end

.add_validations(base) ⇒ Object



17
18
19
20
21
# File 'lib/zuul/active_record/permission_subject.rb', line 17

def self.add_validations(base)
  base.send :validates_presence_of, base.auth_scope.permission_foreign_key.to_sym, base.auth_scope.subject_foreign_key.to_sym
  base.send :validates_uniqueness_of, base.auth_scope.permission_foreign_key.to_sym, :scope => [base.auth_scope.subject_foreign_key.to_sym, :context_id, :context_type], :case_sensitive => false
  base.send :validates_numericality_of, base.auth_scope.permission_foreign_key.to_sym, base.auth_scope.subject_foreign_key.to_sym, :only_integer => true
end

.extended(base) ⇒ Object



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

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