Module: Roles::Generic::User::Implementation::Multi
- Included in:
- RoleStrategy::Generic::EmbedManyRoles::Implementation, RoleStrategy::Generic::ManyRoles::Implementation, RoleStrategy::Generic::RoleStrings::Implementation, RoleStrategy::Generic::RolesMask::Implementation, RoleStrategy::Generic::RolesString::Implementation
- Defined in:
- lib/roles_generic/generic/user/multi_impl.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_list ⇒ Object
Instance Method Details
#add_roles(*roles) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/roles_generic/generic/user/multi_impl.rb', line 4 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
13 14 15 16 17 18 19 |
# File 'lib/roles_generic/generic/user/multi_impl.rb', line 13 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) self.roles = roles_diff(role_names) true end |
#roles_list ⇒ Object
21 22 23 24 |
# File 'lib/roles_generic/generic/user/multi_impl.rb', line 21 def roles_list my_roles = [roles].flat_uniq my_roles.empty? ? [] : my_roles end |