Module: Roles::MongoMapper::Strategy::Single

Instance Method Summary collapse

Methods included from Shared

#get_role, #get_roles, #select_valid_roles, #set_role, #set_roles

Instance Method Details

#add_roles(*role_names) ⇒ Object

assigns first valid role from list of roles



14
15
16
17
18
# File 'lib/roles_mongo_mapper/strategy/single.rb', line 14

def add_roles *role_names
  new_roles = select_valid_roles(role_names) 
  the_role = new_roles.first if !new_roles.empty?
  set_role new_role(the_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_mongo_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_listObject



28
29
30
31
# File 'lib/roles_mongo_mapper/strategy/single.rb', line 28

def roles_list
  raise 'the method #roles should be present' if !respond_to? :roles
  present_roles(roles)
end