Module: RoleStrategy::Mongoid::AdminFlag::Implementation
- Defined in:
- lib/roles_mongoid/strategy/single/admin_flag.rb
Instance Method Summary collapse
- #role_attribute ⇒ Object
-
#roles ⇒ Object
(also: #roles_list)
query assigned roles.
-
#roles=(*new_roles) ⇒ Object
assign roles.
Instance Method Details
#role_attribute ⇒ Object
27 28 29 |
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 27 def role_attribute strategy_class.roles_attribute_name end |
#roles ⇒ Object Also known as: roles_list
query assigned roles
42 43 44 45 |
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 42 def roles role = self.send(role_attribute) ? strategy_class.admin_role_key : strategy_class.default_role_key [role] end |
#roles=(*new_roles) ⇒ Object
assign roles
32 33 34 35 36 37 38 39 |
# File 'lib/roles_mongoid/strategy/single/admin_flag.rb', line 32 def roles=(*new_roles) first_role = new_roles.flatten.first if valid_role?(first_role) self.send("#{role_attribute}=", new_roles.flatten.first.admin?) else raise ArgumentError, "The role #{first_role} is not a valid role" end end |