Skip to content

Instantly share code, notes, and snippets.

@AMHOL AMHOL/dry-validation.rb Secret
Last active Oct 30, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.