Module: RoleStrategy::Mongoid::RoleStrings::Implementation
- Defined in:
- lib/roles_mongoid/strategy/multi/role_strings.rb
Instance Method Summary collapse
- #add_roles(*roles_to_add) ⇒ Object
- #role_attribute ⇒ Object
-
#roles ⇒ Object
query assigned roles.
-
#roles=(*new_roles) ⇒ Object
(also: #role=)
assign roles.
- #roles_list ⇒ Object
Instance Method Details
#add_roles(*roles_to_add) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 43 def add_roles(*roles_to_add) roles_to_add = roles_to_add.flatten.map{|r| r.to_s if valid_role?(r)}.compact if new_roles && new_roles.not.empty? self.send(role_attribute) << new_roles.compact.uniq end end |
#role_attribute ⇒ Object
30 31 32 |
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 30 def role_attribute strategy_class.roles_attribute_name end |
#roles ⇒ Object
query assigned roles
51 52 53 |
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 51 def roles self.send(role_attribute).map{|r| r.to_sym} end |
#roles=(*new_roles) ⇒ Object Also known as: role=
assign roles
35 36 37 38 39 40 |
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 35 def roles=(*new_roles) new_roles = new_roles.flatten.map{|r| r.to_s if valid_role?(r)}.compact if new_roles && new_roles.not.empty? self.send("#{role_attribute}=", new_roles.compact.uniq) end end |
#roles_list ⇒ Object
55 56 57 |
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 55 def roles_list [roles].flatten end |