Module: Roles::ActiveRecord::Strategy::Shared

Included in:
Multi, Single
Defined in:
lib/roles_active_record/strategy/shared.rb

Instance Method Summary collapse

Instance Method Details

#get_roleObject Also known as: get_roles



21
22
23
# File 'lib/roles_active_record/strategy/shared.rb', line 21

def get_role
  r = self.send(role_attribute)
end

#has_any_roles?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/roles_active_record/strategy/shared.rb', line 17

def has_any_roles?
  !has_no_roles?
end

#has_no_roles?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/roles_active_record/strategy/shared.rb', line 13

def has_no_roles?
  get_role.empty?
end

#remove_all_roles!Object



9
10
11
# File 'lib/roles_active_record/strategy/shared.rb', line 9

def remove_all_roles!
  set_empty_role        
end

#select_valid_roles(*roles) ⇒ Object



26
27
28
29
# File 'lib/roles_active_record/strategy/shared.rb', line 26

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 Also known as: set_roles



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

def set_role role
  update_attributes(role_attribute => new_role(role))
end