Exception: LinkedRails::Errors::Forbidden

Inherits:
StandardError
  • Object
show all
Defined in:
lib/linked_rails/errors/forbidden.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ String

Returns the message.

Parameters:

  • options (Hash)

Options Hash (**options):

  • query (String)

    The action of the request

  • record (ActiveRecord::Base)

    The record that was requested

  • policy (Policy)

    The policy that raised the exception

  • message (String)

    Override the default error message

Raises:

  • (StandardError)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/linked_rails/errors/forbidden.rb', line 14

def initialize(**options)
  @query  = options.fetch(:query).to_s
  @record = options[:record]
  @policy = options[:policy]
  @action = @query[-1] == '?' ? @query[0..-2] : @query
  @message = options[:message]

  raise StandardError if @query.blank? && @message.blank?

  super(@message || default_message)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/linked_rails/errors/forbidden.rb', line 6

def action
  @action
end

#policyObject (readonly)

Returns the value of attribute policy.



6
7
8
# File 'lib/linked_rails/errors/forbidden.rb', line 6

def policy
  @policy
end

#queryObject (readonly)

Returns the value of attribute query.



6
7
8
# File 'lib/linked_rails/errors/forbidden.rb', line 6

def query
  @query
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/linked_rails/errors/forbidden.rb', line 6

def record
  @record
end