Module: Roles::Generic::User::Implementation::Single
- Included in:
- RoleStrategy::Generic::AdminFlag, RoleStrategy::Generic::EmbedOneRole, RoleStrategy::Generic::EmbedOneRole::Implementation, RoleStrategy::Generic::OneRole, RoleStrategy::Generic::OneRole::Implementation, RoleStrategy::Generic::RoleString::Implementation
- Defined in:
- lib/roles_generic/generic/user/single_impl.rb
Instance Method Summary collapse
-
#add_roles(*role_names) ⇒ Object
assigns first valid role from list of roles.
-
#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(*role_names) ⇒ Object
assigns first valid role from list of roles
5 6 7 8 |
# File 'lib/roles_generic/generic/user/single_impl.rb', line 5 def add_roles *role_names new_roles = select_valid_roles(role_names) self.role = new_roles.first if !new_roles.empty? 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
12 13 14 15 16 |
# File 'lib/roles_generic/generic/user/single_impl.rb', line 12 def remove_roles *role_names roles = role_names.flat_uniq set_empty_role if roles_diff(roles).empty? true end |
#roles_list ⇒ Object
18 19 20 21 |
# File 'lib/roles_generic/generic/user/single_impl.rb', line 18 def roles_list raise 'the method #roles should be present' if !respond_to? :roles roles end |