Last active
March 24, 2024 22:08
-
-
Save ismasan/3b83cac959cda653f60ee0c57cc922da to your computer and use it in GitHub Desktop.
Input validator step using Parametric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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