Module: Pathway::Plugins::DryValidation::V0_11::InstanceMethods

Extended by:
Forwardable
Defined in:
lib/pathway/plugins/dry_validation/v0_11.rb

Instance Method Summary collapse

Instance Method Details

#validate(state, with: nil) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/pathway/plugins/dry_validation/v0_11.rb', line 67

def validate(state, with: nil)
  if auto_wire && 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 = {}) ⇒ Object



76
77
78
79
80
# File 'lib/pathway/plugins/dry_validation/v0_11.rb', line 76

def validate_with(params, opts = {})
  val = form(opts).call(params)

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