Module: ActiveRecord::Aggregations::HasRoles::InstanceMethods

Defined in:
lib/active_record/aggregations/has_roles.rb

Instance Method Summary collapse

Instance Method Details

#is?(*role_names) ⇒ Boolean

returns true

- when user has administrator role
- when user has one of the supplied roles

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/active_record/aggregations/has_roles.rb', line 51

def is?(*role_names)
  # roles = Rails.cache.fetch("/#{self.class.to_s.tableize}/#{id}/roles") { self.roles.map }
  return true if roles.include?(Role[:administrator])
  Array(role_names).any? { |name| roles.include?(Role[name]) }
end

#is_not?(*role_names) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/active_record/aggregations/has_roles.rb', line 57

def is_not?(*role_names)
  not is?(*role_names)
end