Module: PunditRolePlay::Adapter::ActiveRecordMethods

Defined in:
lib/pundit_role_play/adapter/active_record.rb

Instance Method Summary collapse

Instance Method Details

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/pundit_role_play/adapter/active_record.rb', line 30

def has_role?(role)
  role.to_sym == self.role.underscore.sub(/_role$/, '').to_sym
end

#permissionsObject



38
39
40
41
42
# File 'lib/pundit_role_play/adapter/active_record.rb', line 38

def permissions
  role.constantize.permissions
rescue NoMethodError
  Permissions.new(nil)
end

#pretty_role_nameObject



34
35
36
# File 'lib/pundit_role_play/adapter/active_record.rb', line 34

def pretty_role_name
  role.gsub(/Role/, "")
end

#roleObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pundit_role_play/adapter/active_record.rb', line 14

def role
  value = super

  return nil unless value.present?

  value.constantize

  value
rescue NameError
  # Handle the case where the string can't be converted to a constant
  # eg. "testrole" (which should be "TestRole")
  #
  # Handle the case where the constant does not exist
  raise RoleNotFoundError
end