Module: Zodra::ParamsParser

Defined in:
lib/zodra/params_parser.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.call(raw_params, schema:, strict: Zodra.configuration.strict_params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/zodra/params_parser.rb', line 22

def self.call(raw_params, schema:, strict: Zodra.configuration.strict_params)
  errors = {}
  errors.merge!(check_unknown_keys(raw_params, schema)) if strict
  filtered = filter(raw_params, schema)
  coerced = coerce(filtered, schema)
  errors.merge!(ParamsValidator.call(coerced, schema:))

  if errors.empty?
    apply_defaults(coerced, schema)
    Result.new(params: coerced, errors: {})
  else
    Result.new(params: {}, errors:)
  end
end