Module: Roles::ActiveRecord::Strategy::Single

Instance Method Summary collapse

Methods included from Shared

#get_role, #has_any_roles?, #has_no_roles?, #remove_all_roles!, #select_valid_roles, #set_default_role, #set_role

Instance Method Details

#add_roles(*role_names) ⇒ Object

assigns first valid role from list of roles



15
16
17
18
19
# File 'lib/roles_active_record/strategy/single.rb', line 15

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



23
24
25
26
27
# File 'lib/roles_active_record/strategy/single.rb', line 23

def remove_roles *role_names
  roles = role_names.flat_uniq
  set_empty_role if roles_diff(roles).empty?
  true
end

#roles_listObject



29
30
31
32
# File 'lib/roles_active_record/strategy/single.rb', line 29

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