Module: RoleStrategy::ActiveRecord::RoleString::Implementation

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

Instance Method Summary collapse

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

#add_roles, #remove_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, #set_role

Instance Method Details

#new_role(role) ⇒ Object



30
31
32
33
# File 'lib/roles_active_record/strategy/single/role_string.rb', line 30

def new_role role
  role = role.kind_of?(Array) ? role.first : role
  role.to_s
end

#new_roles(*roles) ⇒ Object



35
36
37
# File 'lib/roles_active_record/strategy/single/role_string.rb', line 35

def new_roles *roles
  new_role roles.flatten.first
end

#present_role(role) ⇒ Object Also known as: present_roles



39
40
41
42
# File 'lib/roles_active_record/strategy/single/role_string.rb', line 39

def present_role role
  return role if role.kind_of? Array
  role.split(',').map(&:to_sym)
end

#set_empty_roleObject



44
45
46
# File 'lib/roles_active_record/strategy/single/role_string.rb', line 44

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