Class: Committee::SchemaValidator::HyperSchema::StringParamsCoercer

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/schema_validator/hyper_schema/string_params_coercer.rb

Overview

StringParamsCoercer takes parameters that are specified over a medium that can only accept strings (for example in a URL path or in query parameters) and attempts to coerce them into known types based of a link’s schema definition.

Currently supported types: null, integer, number and boolean.

call returns a hash of all params which could be coerced - coercion errors are simply ignored and expected to be handled later by schema validation.

Instance Method Summary collapse

Constructor Details

#initialize(query_hash, schema, options = {}) ⇒ StringParamsCoercer

Returns a new instance of StringParamsCoercer.



17
18
19
20
21
22
# File 'lib/committee/schema_validator/hyper_schema/string_params_coercer.rb', line 17

def initialize(query_hash, schema, options = {})
  @query_hash = query_hash
  @schema = schema

  @coerce_recursive = options.fetch(:coerce_recursive, false)
end

Instance Method Details

#call!Object



24
25
26
# File 'lib/committee/schema_validator/hyper_schema/string_params_coercer.rb', line 24

def call!
  coerce_object!(@query_hash, @schema)
end