Skip to content

Instantly share code, notes, and snippets.

@groony
Last active July 2, 2018 11:47
Show Gist options
  • Save groony/db3c44b7ee5d5a20f60c28d08a81cfb3 to your computer and use it in GitHub Desktop.
Save groony/db3c44b7ee5d5a20f60c28d08a81cfb3 to your computer and use it in GitHub Desktop.
high level rules order
schema = Dry::Validation.Schema(Dry::Validation::Schema::Params) do
configure do
option :user
def exists?(value)
# your code
end
def free?(uid, value)
# your code
end
end
required(:provider).filled(:str?)
required(:uid).filled(:str?)
optional(:token).maybe(:str?)
rule(identity_taken: %i[provider token]) do |provider, token|
token.exists? > provider.free?(value(:uid))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment