Sha256: a5cb068920d28a69821e6ed9baba0da1b9b4b261903699de2810c0bbf0ac9957

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module Zuul
  module ActiveRecord
    module PermissionRole
      def self.included(base)
        base.send :extend, ClassMethods
        base.send :include, ContextMethods # defined in lib/zuul/active_record.rb
      end

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

        def self.add_validations(base)
          base.send :validates_presence_of, base.auth_scope.permission_foreign_key.to_sym, base.auth_scope.role_foreign_key.to_sym
          base.send :validates_uniqueness_of, base.auth_scope.permission_foreign_key.to_sym, :scope => [base.auth_scope.role_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.role_foreign_key.to_sym, :only_integer => true
        end

        def self.add_associations(base)
          base.send :belongs_to, base.auth_scope.permission_class_name.underscore.to_sym.to_s.split("/").last.to_sym, :class_name => base.auth_scope.permission_class_name
          base.send :belongs_to, base.auth_scope.role_class_name.underscore.to_sym.to_s.split("/").last.to_sym, :class_name => base.auth_scope.role_class_name
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zuul-0.2.5 lib/zuul/active_record/permission_role.rb