Module: RoleStrategy::MongoMapper::EmbedOneRole::Implementation
Instance Method Summary
collapse
#remove_roles, #roles_list
#get_role, #get_roles, #set_roles
Instance Method Details
#add_roles(*role_names) ⇒ Object
41
42
43
44
45
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 41
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
|
#new_role(role) ⇒ Object
54
55
56
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 54
def new_role role
role_class.find_role( role)
end
|
#new_roles(*roles) ⇒ Object
58
59
60
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 58
def new_roles *roles
new_role roles.flatten.first
end
|
#present_roles(*roles) ⇒ Object
62
63
64
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 62
def present_roles *roles
roles.map{|role| role}
end
|
#select_valid_roles(*role_names) ⇒ Object
70
71
72
73
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 70
def select_valid_roles *role_names
role_names = role_names.flat_uniq.select{|role| valid_role? role }
has_role_class? ? role_class.find_roles(role_names).to_a : role_names
end
|
#set_empty_role ⇒ Object
66
67
68
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 66
def set_empty_role
self.send("#{role_attribute}=", nil)
end
|
#set_role(role) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/roles_mongo_mapper/strategy/single/embed_one_role.rb', line 47
def set_role role
raise ArgumentError, "#set_role only takes a single role as argument, not #{role}" if role.kind_of?(Array)
the_role = new_role(role)
self.send("#{role_attribute}=", the_role)
end
|