Skip to content

Instantly share code, notes, and snippets.

@ismasan
Last active March 24, 2024 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/3b83cac959cda653f60ee0c57cc922da to your computer and use it in GitHub Desktop.
Save ismasan/3b83cac959cda653f60ee0c57cc922da to your computer and use it in GitHub Desktop.
Input validator step using Parametric
# https://github.com/ismasan/parametric
require 'parametric'
class InputValidator
def initialize(&block)
@schema = Parametric::Schema.new(&block)
end
# @param result [Result]
# @return [Result]
def call(result)
params = result.params
out = @schema.resolve(params)
if out.valid?
result.continue(params: params.merge(out.output))
else
result.halt(errors: result.errors.merge(out.errors))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment