Module: RoleStrategy::ActiveRecord::ManyRoles::Implementation

Includes:
Roles::ActiveRecord::Strategy::Multi
Defined in:
lib/roles_active_record/strategy/multi/many_roles.rb

Instance Method Summary collapse

Methods included from Roles::ActiveRecord::Strategy::Multi

#add_roles, #remove_roles, #roles, #roles_list

Methods included from Roles::ActiveRecord::Strategy::Shared

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

Instance Method Details

#new_roles(*role_names) ⇒ Object



37
38
39
# File 'lib/roles_active_record/strategy/multi/many_roles.rb', line 37

def new_roles *role_names
  role_class.find_roles(extract_roles role_names)
end

#present_roles(roles_names) ⇒ Object



41
42
43
# File 'lib/roles_active_record/strategy/multi/many_roles.rb', line 41

def present_roles roles_names
  roles_names.to_a.map{|role| role.name.to_s.to_sym}
end

#roles=(*role_names) ⇒ Object

assign multiple roles



28
29
30
31
32
33
34
35
# File 'lib/roles_active_record/strategy/multi/many_roles.rb', line 28

def roles=(*role_names)
  role_names = role_names.flat_uniq
  role_names = extract_roles(role_names)
  return nil if role_names.empty?
  valids = role_class.find_roles(role_names).to_a
  vrs = select_valid_roles role_names
  set_roles(vrs)
end

#set_empty_rolesObject Also known as: set_empty_role



45
46
47
# File 'lib/roles_active_record/strategy/multi/many_roles.rb', line 45

def set_empty_roles
  self.send("#{role_attribute}=", [])
end