Module: RoleStrategy::ActiveRecord::OneRole::Implementation

Includes:
Roles::ActiveRecord::Strategy::Single
Defined in:
lib/roles_active_record/strategy/single/one_role.rb

Instance Method Summary collapse

Methods included from Roles::ActiveRecord::Strategy::Single

#add_roles, #roles_list

Methods included from Roles::ActiveRecord::Strategy::Shared

#get_role, #has_any_roles?, #has_no_roles?, #remove_all_roles!, #select_valid_roles, #set_default_role

Instance Method Details

#new_role(role) ⇒ Object



37
38
39
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 37

def new_role role
  role_class.find_role(extract_role role)
end

#new_roles(*roles) ⇒ Object



41
42
43
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 41

def new_roles *roles
  new_role roles.flatten.first
end

#present_roles(*roles) ⇒ Object



51
52
53
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 51

def present_roles *roles
  roles.map{|role| extract_role role}
end

#remove_roles(*role_names) ⇒ Object



45
46
47
48
49
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 45

def remove_roles *role_names
  roles = role_names.flat_uniq
  set_empty_role if roles_diff(roles).empty?
  true
end

#set_empty_roleObject



55
56
57
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 55

def set_empty_role
  self.send("#{role_attribute}=", nil)
end

#set_role(role) ⇒ Object Also known as: set_roles



28
29
30
31
32
33
34
# File 'lib/roles_active_record/strategy/single/one_role.rb', line 28

def set_role role 
  # set_empty_role
  role = role.first if role.kind_of? Array
  # puts "set_role: #{role.inspect}"        
  self.send("#{role_attribute}=", role)
  # role.users << self
end