Exception: Pundit::NotAuthorizedError

Inherits:
Error
  • Object
show all
Defined in:
lib/pundit.rb

Overview

Error that will be raised when authorization has failed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ NotAuthorizedError

Returns a new instance of NotAuthorizedError.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pundit.rb', line 31

def initialize(options = {})
  if options.is_a? String
    message = options
  else
    @query  = options[:query]
    @record = options[:record]
    @policy = options[:policy]

    message = options.fetch(:message) do
      record_name = record.is_a?(Class) ? record.to_s : "this #{record.class}"
      "not allowed to #{policy.class}##{query} #{record_name}"
    end
  end

  super(message)
end

Instance Attribute Details

#policyObject (readonly)



29
30
31
# File 'lib/pundit.rb', line 29

def policy
  @policy
end

#queryObject (readonly)



29
30
31
# File 'lib/pundit.rb', line 29

def query
  @query
end

#recordObject (readonly)



29
30
31
# File 'lib/pundit.rb', line 29

def record
  @record
end