33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/roles_mongoid/base.rb', line 33
def strategy name, options = {}
strategy_name = name.to_sym
raise ArgumentError, "Unknown role strategy #{strategy_name}" if !MAP.keys.include? strategy_name
use_roles_strategy strategy_name
set_role_class(strategy_name, options) if strategies_with_role_class.include? strategy_name
if default_options?(options) && MAP[strategy_name]
instance_eval statement(MAP[strategy_name])
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, options
end
|