Module: Roles::Mongoid::Strategy::Shared

Included in:
Single
Defined in:
lib/roles_mongoid/strategy/shared.rb

Instance Method Summary collapse

Instance Method Details

#get_roleObject



15
16
17
# File 'lib/roles_mongoid/strategy/shared.rb', line 15

def get_role
  r = self.send(role_attribute) 
end

#get_rolesObject



19
20
21
# File 'lib/roles_mongoid/strategy/shared.rb', line 19

def get_roles
  r = self.send(role_attribute)
end

#select_valid_roles(*roles) ⇒ Object



23
24
25
26
# File 'lib/roles_mongoid/strategy/shared.rb', line 23

def select_valid_roles *roles
  roles.flat_uniq.select{|role| valid_role? role }
  has_role_class? ? role_class.find_roles(roles).to_a.flat_uniq : roles.flat_uniq
end

#set_role(role) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
# File 'lib/roles_mongoid/strategy/shared.rb', line 4

def set_role role
  raise ArgumentError, "#set_role only takes a single role as argument, not #{role}" if role.kind_of?(Array)
  self.send("#{role_attribute}=", role)
end

#set_roles(*roles) ⇒ Object



9
10
11
12
13
# File 'lib/roles_mongoid/strategy/shared.rb', line 9

def set_roles *roles
  roles = roles.flat_uniq
  roles = roles.first if self.class.role_strategy.multiplicity == :single        
  self.send("#{role_attribute}=", roles)
end