Module: Pathway::Plugins::DryValidation::V1_0::InstanceMethods
- Extended by:
- Forwardable
- Defined in:
- lib/pathway/plugins/dry_validation/v1_0.rb
Instance Method Summary collapse
Instance Method Details
#validate(state, with: nil) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/pathway/plugins/dry_validation/v1_0.rb', line 58 def validate(state, with: nil) if auto_wire && .any? with ||= .zip().to_h end opts = Hash(with).map { |to, from| [to, state[from]] }.to_h validate_with(state[:input], **opts) .then { |params| state.update(params: params) } end |
#validate_with(input, **opts) ⇒ Object
67 68 69 70 71 |
# File 'lib/pathway/plugins/dry_validation/v1_0.rb', line 67 def validate_with(input, **opts) result = contract(**opts).call(input) result.success? ? wrap(result.values.to_h) : error(:validation, details: result.errors.to_h) end |