Class: Grape::Validations::Types::DryTypeCoercer
- Inherits:
-
Object
- Object
- Grape::Validations::Types::DryTypeCoercer
- Defined in:
- lib/grape/validations/types/dry_type_coercer.rb
Overview
A base class for classes which must identify a coercer to be used. If the strict
argument is true, it won’t coerce the given value but check its type. More information there dry-rb.org/gems/dry-types/1.2/built-in-types/
Direct Known Subclasses
Instance Method Summary collapse
-
#call(val) ⇒ Object
Coerces the given value to a type which was specified during initialization as a type argument.
-
#initialize(type, strict = false) ⇒ DryTypeCoercer
constructor
A new instance of DryTypeCoercer.
Constructor Details
#initialize(type, strict = false) ⇒ DryTypeCoercer
Returns a new instance of DryTypeCoercer.
20 21 22 23 |
# File 'lib/grape/validations/types/dry_type_coercer.rb', line 20 def initialize(type, strict = false) @type = type @scope = strict ? DryTypes::Strict : DryTypes::Params end |
Instance Method Details
#call(val) ⇒ Object
Coerces the given value to a type which was specified during initialization as a type argument.
29 30 31 32 33 |
# File 'lib/grape/validations/types/dry_type_coercer.rb', line 29 def call(val) @coercer[val] rescue Dry::Types::CoercionError => _e InvalidValue.new end |