-
-
Save AMHOL/fdf0a90292914ad758ec to your computer and use it in GitHub Desktop.
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
class UserValidator | |
include Dry::Validation | |
rules << { | |
title: { | |
inclusion: %w(Mr Mrs Miss Ms Dr) | |
}, | |
first_name: { | |
presence: true | |
}, | |
last_name: { | |
presence: true | |
}, | |
username: { | |
email: true | |
} | |
} | |
end | |
class RegistrationValidator < UserValidator | |
rules << { | |
username: { | |
rescues: { | |
exception: PG::UniqueViolation, | |
as: :unique | |
} | |
}, | |
password: { | |
length: 8..40 | |
} | |
} | |
end | |
RegistrationValidator.new(params).transaction do | |
rescue Dry::Validation::Error => e | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment