Module: RoleStrategy::Mongoid::RoleStrings::Implementation

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

Instance Method Summary collapse

Instance Method Details

#add_roles(*roles_to_add) ⇒ Object



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

def add_roles(*roles_to_add)
  roles_to_add = roles_to_add.flatten.map{|r| r.to_s if valid_role?(r)}.compact
  if new_roles && new_roles.not.empty?
    self.send(role_attribute) << new_roles.compact.uniq
  end
end

#rolesObject

query assigned roles



47
48
49
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 47

def roles
  self.send(role_attribute).map{|r| r.to_sym}
end

#roles=(*new_roles) ⇒ Object Also known as: role=

assign roles



31
32
33
34
35
36
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 31

def roles=(*new_roles)
  new_roles = new_roles.flatten.map{|r| r.to_s if valid_role?(r)}.compact
  if new_roles && new_roles.not.empty?
    self.send("#{role_attribute}=", new_roles.compact.uniq) 
  end
end

#roles_listObject



51
52
53
# File 'lib/roles_mongoid/strategy/multi/role_strings.rb', line 51

def roles_list     
  [roles].flatten
end