Last active
July 2, 2018 11:47
-
-
Save groony/db3c44b7ee5d5a20f60c28d08a81cfb3 to your computer and use it in GitHub Desktop.
high level rules order
This file contains hidden or 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
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