Module: Roles::DataMapper::Strategy::Single
- Includes:
- Shared
- Included in:
- RoleStrategy::DataMapper::AdminFlag::Implementation, RoleStrategy::DataMapper::OneRole::Implementation, RoleStrategy::DataMapper::RoleString::Implementation
- Defined in:
- lib/roles_data_mapper/strategy/single.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
Methods included from Shared
#get_role, #get_roles, #select_valid_roles, #set_role
Instance Method Details
#add_roles(*role_names) ⇒ Object
assigns first valid role from list of roles
14 15 16 17 18 |
# File 'lib/roles_data_mapper/strategy/single.rb', line 14 def add_roles *role_names new_roles = select_valid_roles(role_names) new_role = new_roles.first if !new_roles.empty? set_role new_role 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 |
# File 'lib/roles_data_mapper/strategy/single.rb', line 22 def remove_roles *role_names roles = role_names.flat_uniq set_empty_role if roles_diff(roles).empty? true end |
#roles_list ⇒ Object
28 29 30 31 |
# File 'lib/roles_data_mapper/strategy/single.rb', line 28 def roles_list raise 'the method #roles should be present' if !respond_to? :roles present_roles(roles) end |