Module: RoleStrategy::MongoMapper::AdminFlag::Implementation
Instance Method Summary
collapse
#add_roles, #remove_roles, #roles_list
#get_roles, #select_valid_roles, #set_role
Instance Method Details
#get_role ⇒ Object
50
51
52
|
# File 'lib/roles_mongo_mapper/strategy/single/admin_flag.rb', line 50
def get_role
self.send(role_attribute) ? strategy_class.admin_role_key : strategy_class.default_role_key
end
|
#new_role(role) ⇒ Object
45
46
47
48
|
# File 'lib/roles_mongo_mapper/strategy/single/admin_flag.rb', line 45
def new_role role
role = role.kind_of?(Array) ? role.flatten.first : role
role.kind_of?(Symbol) ? role.admin? : role
end
|
#present_roles(*roles) ⇒ Object
54
55
56
57
|
# File 'lib/roles_mongo_mapper/strategy/single/admin_flag.rb', line 54
def present_roles *roles
roles = roles.flat_uniq
roles.map{|role| role ? :admin : :guest}
end
|
#roles=(*role_names) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/roles_mongo_mapper/strategy/single/admin_flag.rb', line 33
def roles=(*role_names)
role_names = role_names.flat_uniq
role_names = (role_names)
return nil if role_names.empty?
vrs = select_valid_roles role_names
set_roles(vrs)
end
|
#set_empty_role ⇒ Object
59
60
61
|
# File 'lib/roles_mongo_mapper/strategy/single/admin_flag.rb', line 59
def set_empty_role
self.send("#{role_attribute}=", false)
end
|
#set_roles(*roles) ⇒ Object
41
42
43
|
# File 'lib/roles_mongo_mapper/strategy/single/admin_flag.rb', line 41
def set_roles *roles
set_role roles.flatten.first
end
|