-
-
Save CucumisSativus/a06a2cea58ac18e0f6000c032db21e2d 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
PostcardSchema = Dry::Validation.Schema do | |
configure do | |
config.messages_file = (ForbiddenWord).root.join('config/locales/errors.yml') | |
def state_required?(country) | |
country.is_state_required | |
end | |
end | |
required(:address).filled | |
required(:city).filled | |
required(:zip_code).filled(format?: ZIP_CODE_FORMAT) | |
required(:content).filled(min_size?: MINIMAL_CONTENT_LENGTH) | |
required(:country).filled | |
required(:country).maybe(:state_required?) | |
rule(country_requires_state: [:country, :state]) do |country, state| | |
country.state_required?.then(state.filled?) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment