Module: Pathway::Plugins::DryValidation::InstanceMethods
- Extended by:
- Forwardable
- Defined in:
- lib/pathway/plugins/dry_validation.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.rb', line 58 def validate(state, with: nil) if && .any? with ||= .zip().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
67 68 69 70 71 |
# File 'lib/pathway/plugins/dry_validation.rb', line 67 def validate_with(params, opts = {}) val = form(opts).call(params) val.success? ? wrap(val.output) : error(:validation, details: val.) end |