Module: RoleStrategy::MongoMapper::OneRole::ClassMethods

Defined in:
lib/roles_mongo_mapper/strategy/single/one_role.rb

Instance Method Summary collapse

Instance Method Details

#in_any_role(*role_names) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/roles_mongo_mapper/strategy/single/one_role.rb', line 29

def in_any_role(*role_names)
  begin
    role_ids = Role.find_roles(role_names).map(&:id)
    all("#{role_attribute}._id" => role_ids)
    # all(role_id_attribute.in => role_ids)
  rescue 
    return []
  end
end

#in_role(role_name) ⇒ Object



25
26
27
# File 'lib/roles_mongo_mapper/strategy/single/one_role.rb', line 25

def in_role(role_name)  
  in_any_role(role_name)
end

#role_attributeObject



17
18
19
# File 'lib/roles_mongo_mapper/strategy/single/one_role.rb', line 17

def role_attribute
  strategy_class.roles_attribute_name.to_sym
end

#role_id_attributeObject



21
22
23
# File 'lib/roles_mongo_mapper/strategy/single/one_role.rb', line 21

def role_id_attribute
  "#{role_attribute}_id".to_sym
end