Exception: Grape::Exceptions::Validation

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/exceptions/validation.rb

Constant Summary

Constants inherited from Base

Base::BASE_ATTRIBUTES_KEY, Base::BASE_MESSAGES_KEY, Base::FALLBACK_LOCALE

Instance Attribute Summary collapse

Attributes inherited from Base

#headers, #message, #status

Instance Method Summary collapse

Methods inherited from Base

#[]

Constructor Details

#initialize(params:, message: nil, **args) ⇒ Validation

Returns a new instance of Validation



9
10
11
12
13
14
15
16
# File 'lib/grape/exceptions/validation.rb', line 9

def initialize(params:, message: nil, **args)
  @params = params
  if message
    @message_key = message if message.is_a?(Symbol)
    args[:message] = translate_message(message)
  end
  super(args)
end

Instance Attribute Details

#message_keyObject

Returns the value of attribute message_key



7
8
9
# File 'lib/grape/exceptions/validation.rb', line 7

def message_key
  @message_key
end

#paramsObject

Returns the value of attribute params



6
7
8
# File 'lib/grape/exceptions/validation.rb', line 6

def params
  @params
end

Instance Method Details

#as_json(*_args) ⇒ Object

remove all the unnecessary stuff from Grape::Exceptions::Base like status and headers when converting a validation error to json or string



20
21
22
# File 'lib/grape/exceptions/validation.rb', line 20

def as_json(*_args)
  to_s
end

#to_sObject



24
25
26
# File 'lib/grape/exceptions/validation.rb', line 24

def to_s
  message
end