Module: Roles::MongoMapper::ClassMethods
- Defined in:
- lib/roles_mongo_mapper/base.rb
Constant Summary collapse
- MAP =
{ :admin_flag => "key :admin_flag, Boolean", # :embed_many_roles => "many :many_roles, :class_name => 'Role'", # :embed_one_role => "one :one_role, :class_name => 'Role'", :roles_mask => "key :roles_mask, Integer, :default => 0", :role_string => "key :role_string, String", :role_strings => "key :role_strings, Array", :roles_string => "key :roles_string, String" }
Instance Method Summary collapse
- #strategy(name, options = {}) ⇒ Object
- #valid_multi_strategies ⇒ Object
- #valid_single_strategies ⇒ Object
- #valid_strategies ⇒ Object
Instance Method Details
#strategy(name, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/roles_mongo_mapper/base.rb', line 40 def strategy name, = {} strategy_name = name.to_sym raise ArgumentError, "Unknown role strategy #{strategy_name}" if !valid_strategies.include? strategy_name use_roles_strategy strategy_name set_role_class(strategy_name, ) if strategies_with_role_class.include? strategy_name if () && MAP[strategy_name] instance_eval statement(MAP[strategy_name]) end # one_role reference if strategy_name == :one_role key :one_role_id, ObjectId key :one_role, @role_class_name end # many_roles references if strategy_name == :many_roles instance_eval %{ key :many_roles_ids, Array, :typecast => 'ObjectId' many :many_roles, :class_name => '#{@role_class_name}', :in => :many_roles_ids ensure_index :many_role_ids } end # case name # when :embed_one_role # raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !@role_class_name # @role_class_name.embedded_in :user, :inverse_of => :one_role # when :embed_many_roles # raise ArgumentError, "#strategy class method must take :role_class option when using an embedded role strategy" if !@role_class_name # @role_class_name.embedded_in :user, :inverse_of => :many_roles # end set_role_strategy strategy_name, end |
#valid_multi_strategies ⇒ Object
32 33 34 |
# File 'lib/roles_mongo_mapper/base.rb', line 32 def valid_multi_strategies [:many_roles, :roles_mask, :role_strings] end |
#valid_single_strategies ⇒ Object
28 29 30 |
# File 'lib/roles_mongo_mapper/base.rb', line 28 def valid_single_strategies [:admin_flag, :one_role, :role_string] end |
#valid_strategies ⇒ Object
36 37 38 |
# File 'lib/roles_mongo_mapper/base.rb', line 36 def valid_strategies valid_single_strategies + valid_multi_strategies end |