Module: Roles::MongoMapper::Strategy::Multi
- Included in:
- RoleStrategy::MongoMapper::ManyRoles::Implementation, RoleStrategy::MongoMapper::RoleStrings::Implementation, RoleStrategy::MongoMapper::RolesMask::Implementation
- Defined in:
- lib/roles_mongo_mapper/strategy/multi.rb
Instance Method Summary collapse
- #add_roles(*roles) ⇒ Object
-
#remove_roles(*role_names) ⇒ Object
should remove the current single role (set = nil) only if it is contained in the list of roles to be removed.
-
#roles ⇒ Object
query assigned roles.
-
#roles=(*role_names) ⇒ Object
assign multiple roles.
- #roles_list ⇒ Object
Instance Method Details
#add_roles(*roles) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/roles_mongo_mapper/strategy/multi.rb', line 13 def add_roles *roles new_roles = select_valid_roles(roles) if !new_roles.empty? self.roles = self.roles + new_roles end end |
#remove_roles(*role_names) ⇒ Object
should remove the current single role (set = nil) only if it is contained in the list of roles to be removed
22 23 24 25 26 27 28 29 30 |
# File 'lib/roles_mongo_mapper/strategy/multi.rb', line 22 def remove_roles *role_names role_names = role_names.flat_uniq set_empty_roles and return if roles_diff(role_names).empty? roles_to_remove = select_valid_roles(role_names) diff = roles_diff(role_names) diff = role_class.find_roles(diff).to_a if self.class.role_strategy.type == :complex set_roles(diff) true end |
#roles ⇒ Object
query assigned roles
33 34 35 36 37 |
# File 'lib/roles_mongo_mapper/strategy/multi.rb', line 33 def roles get_roles.to_a.map do |role| role.respond_to?(:sym) ? role.to_sym : role end end |
#roles=(*role_names) ⇒ Object
assign multiple roles
7 8 9 10 11 |
# File 'lib/roles_mongo_mapper/strategy/multi.rb', line 7 def roles=(*role_names) extracted_roles = extract_roles(role_names) return nil if extracted_roles.empty? set_roles(select_valid_roles extracted_roles) end |
#roles_list ⇒ Object
39 40 41 42 43 |
# File 'lib/roles_mongo_mapper/strategy/multi.rb', line 39 def roles_list my_roles = [roles].flat_uniq return [] if my_roles.empty? has_role_class? ? my_roles.map{|r| r.name.to_sym } : my_roles end |