Module: RoleStrategy::Mongoid::OneRole::Implementation
- Defined in:
- lib/roles_mongoid/strategy/single/one_role.rb
Instance Method Summary collapse
-
#roles ⇒ Object
query assigned roles.
-
#roles=(*_roles) ⇒ Object
(also: #role=)
assign roles.
- #roles_list ⇒ Object
Instance Method Details
#roles ⇒ Object
query assigned roles
45 46 47 48 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 45 def roles role = self.send(role_attribute) role ? [role.name.to_sym] : [] end |
#roles=(*_roles) ⇒ Object Also known as: role=
assign roles
33 34 35 36 37 38 39 40 41 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 33 def roles=(*_roles) _roles = get_roles(_roles) return nil if roles.none? first_role = _roles.flatten.first role_relation = role_class.find_role(first_role) self.send("#{role_attribute}=", role_relation) one_role.save end |
#roles_list ⇒ Object
50 51 52 |
# File 'lib/roles_mongoid/strategy/single/one_role.rb', line 50 def roles_list self.roles.to_a end |