Module: Roles::Generic::ClassMethods
- Defined in:
- lib/roles_generic/generic.rb
Constant Summary collapse
- MAP =
{ :admin_flag => "attr_accessor :admin_flag", :many_roles => "attr_accessor :many_roles", :one_role => "attr_accessor :one_role", :roles_mask => "attr_accessor :roles_mask", :role_string => "attr_accessor :role_string", :role_strings => "attr_accessor :role_strings", :roles_string => "attr_accessor :roles_string", :embed_many_roles => "attr_accessor :many_roles", :embed_one_role => "attr_accessor :one_role" }
Instance Attribute Summary collapse
-
#role_groups ⇒ Object
Returns the value of attribute role_groups.
Instance Method Summary collapse
-
#add_role_group(group_hash) ⇒ Object
role_group :admin => :admin, :super_admin.
- #add_role_groups(groups_hash) ⇒ Object
- #strategy(name, options = {}) ⇒ Object
Instance Attribute Details
#role_groups ⇒ Object
Returns the value of attribute role_groups.
29 30 31 |
# File 'lib/roles_generic/generic.rb', line 29 def role_groups @role_groups end |
Instance Method Details
#add_role_group(group_hash) ⇒ Object
role_group :admin => :admin, :super_admin
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/roles_generic/generic.rb', line 62 def add_role_group(group_hash) raise ArgumentError, '#add_role_group must be passed a Hash where the key is the group name' if !group_hash.kind_of? Hash raise ArgumentError, '#add_role_group must be a Hash with a single key value pair' if group_hash.size > 1 # first key/value pair? group = group_hash.keys.first # see sugar_high raise ArgumentError, "Role group identifier must be a String or Symbol " if !group.kind_of_label? role_list = group_hash.values.first hash = {group.to_sym => [role_list].flat_uniq.to_symbols} role_groups.merge!(hash) end |
#add_role_groups(groups_hash) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/roles_generic/generic.rb', line 54 def add_role_groups(groups_hash) raise ArgumentError, "Role group must be passed a Hash where the key is the group name" if !groups_hash.kind_of? Hash groups_hash.each_pair do |key, list| add_role_group(key => list) end end |
#strategy(name, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/roles_generic/generic.rb', line 34 def strategy name, = {} strategy_name = name.to_sym raise ArgumentError, "Unknown role strategy #{strategy_name}" if !MAP.keys.include? strategy_name use_roles_strategy strategy_name if () && MAP[strategy_name] instance_eval MAP[strategy_name] end if strategies_with_role_class.include? strategy_name if !.kind_of? Symbol @role_class_name = get_role_class() else @role_class_name = default_role_class if strategies_with_role_class.include? strategy_name end end set_role_strategy name, end |