module Pathway::Plugins::DryValidation::V0_11::InstanceMethods

Public Instance Methods

validate(state, with: nil) click to toggle source
# File lib/pathway/plugins/dry_validation/v0_11.rb, line 63
def validate(state, with: nil)
  if auto_wire_options && form_options.any?
    with ||= form_options.zip(form_options).to_h
  end
  opts = Hash(with).map { |opt, key| [opt, state[key]] }.to_h
  validate_with(state[:input], opts)
    .then { |params| state.update(params: params) }
end
validate_with(params, opts = {}) click to toggle source
# File lib/pathway/plugins/dry_validation/v0_11.rb, line 72
def validate_with(params, opts = {})
  val = form(opts).call(params)

  val.success? ? wrap(val.output) : error(:validation, details: val.messages)
end