32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/roles_mongoid/base.rb', line 32
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
if strategies_with_role_class.include? strategy_name
if !options.kind_of? Symbol
@role_class_name = get_role_class(strategy_name, options)
else
@role_class_name = default_role_class(strategy_name)
end
end
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
|