Module: RoleStrategy::ActiveRecord::OneRole::Implementation
Instance Method Summary
collapse
#add_roles, #roles_list
#get_role, #has_any_roles?, #has_no_roles?, #remove_all_roles!, #select_valid_roles, #set_default_role
Instance Method Details
#new_role(role) ⇒ Object
37
38
39
|
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 37
def new_role role
role_class.find_role( role)
end
|
#new_roles(*roles) ⇒ Object
41
42
43
|
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 41
def new_roles *roles
new_role roles.flatten.first
end
|
#present_roles(*roles) ⇒ Object
51
52
53
|
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 51
def present_roles *roles
roles.map{|role| role}
end
|
#remove_roles(*role_names) ⇒ Object
45
46
47
48
49
|
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 45
def remove_roles *role_names
roles = role_names.flat_uniq
set_empty_role if roles_diff(roles).empty?
true
end
|
#set_empty_role ⇒ Object
55
56
57
|
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 55
def set_empty_role
self.send("#{role_attribute}=", nil)
end
|
#set_role(role) ⇒ Object
Also known as:
set_roles
28
29
30
31
32
33
34
|
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 28
def set_role role
role = role.first if role.kind_of? Array
self.send("#{role_attribute}=", role)
end
|