Sha256: 8d45eca69f26ca3d650a345bfea47daf0156e00e7fd1fac4da2052125cd44e3c

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module Roles::Base
  def valid_roles_are(*role_list)
    strategy_class.valid_roles = role_list.to_symbols
  end
end

module Roles
  module Mongoid  
    def self.included(base) 
      base.extend Roles::Base
      base.extend ClassMethods
      base.orm_name = :mongoid
    end

    module ClassMethods
      
      MAP = {
        :admin_flag   => "field :admin_flag, :type => Boolean",
        :many_roles   => "references_many :many_roles, :stored_as => :array, :class_name => 'Role', :default => []",
        :one_role     => "references_one :one_role, :class_name => 'Role'",
        :roles_mask   => "field :roles_mask, :type => Integer, :default => 1",
        :role_string  => "field :role_string, :type => String",
        :role_strings => "field :role_strings, :type => Array",
        :roles_string => "field :roles_string, :type => String"
      }
      
      def strategy name, options=nil
        if options == :default && MAP[name]
          instance_eval MAP[name] 
        end
        role_strategy name, options
      end    
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
roles_mongoid-0.2.4 lib/roles_mongoid/base.rb
roles_for_mongoid-0.2.3 lib/roles_mongoid/base.rb
roles_for_mongoid-0.2.2 lib/roles_mongoid/base.rb
roles_for_mongoid-0.2.1 lib/roles_mongoid/base.rb
roles_for_mongoid-0.2.0 lib/roles_mongoid/base.rb