Module: RoleStrategy::Mongoid::ManyRoles::Implementation

Defined in:
lib/roles_mongoid/strategy/multi/many_roles.rb

Instance Method Summary collapse

Instance Method Details

#add_roles(*roles) ⇒ Object



46
47
48
49
50
51
# File 'lib/roles_mongoid/strategy/multi/many_roles.rb', line 46

def add_roles(*roles)  
  raise "Role class #{role_class} does not have a #find_role(role) method" if !role_class.respond_to? :find_role
  role_relations = role_class.find_roles(*roles)
  self.send(role_attribute) << role_relations
  save
end

#role_attributeObject



32
33
34
# File 'lib/roles_mongoid/strategy/multi/many_roles.rb', line 32

def role_attribute
  strategy_class.roles_attribute_name
end

#rolesObject

query assigned roles



54
55
56
# File 'lib/roles_mongoid/strategy/multi/many_roles.rb', line 54

def roles
  self.send(role_attribute)
end

#roles=(*_roles) ⇒ Object

assign roles



37
38
39
40
41
42
43
44
# File 'lib/roles_mongoid/strategy/multi/many_roles.rb', line 37

def roles=(*_roles) 
  _roles = get_roles(_roles)
  return nil if roles.none?                
  
  role_relations = role_class.find_roles(_roles) 
  self.send("#{role_attribute}=", role_relations)
  save
end

#roles_listObject



58
59
60
# File 'lib/roles_mongoid/strategy/multi/many_roles.rb', line 58

def roles_list     
  [roles].flatten.map{|r| r.name }.compact.to_symbols
end