Class: Grape::Validations::CoerceOptions

Inherits:
Data
  • Object
show all
Defined in:
lib/grape/validations/coerce_options.rb

Overview

Immutable value object describing how a parameter is coerced. Assembled by ValidationsSpec#coerce_options from the parsed type/coerce_with/ coerce_message declaration — never written by the user — and consumed by ParamsScope#check_coerce_with / ParamsScope#validate_coerce and by Validators::Validators::CoerceValidator (which receives it as its options argument).

All three fields may be nil (e.g. a remountable API evaluated on its base instance has no resolved type yet). coerce_method (not method) avoids shadowing Object#method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, coerce_method: nil, message: nil) ⇒ CoerceOptions

Returns a new instance of CoerceOptions.



16
17
18
# File 'lib/grape/validations/coerce_options.rb', line 16

def initialize(type: nil, coerce_method: nil, message: nil)
  super
end

Instance Attribute Details

#coerce_methodObject (readonly)

Returns the value of attribute coerce_method

Returns:

  • (Object)

    the current value of coerce_method



15
16
17
# File 'lib/grape/validations/coerce_options.rb', line 15

def coerce_method
  @coerce_method
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



15
16
17
# File 'lib/grape/validations/coerce_options.rb', line 15

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



15
16
17
# File 'lib/grape/validations/coerce_options.rb', line 15

def type
  @type
end