Skip to content

Instantly share code, notes, and snippets.

@CucumisSativus
Last active August 31, 2016 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CucumisSativus/a06a2cea58ac18e0f6000c032db21e2d to your computer and use it in GitHub Desktop.
Save CucumisSativus/a06a2cea58ac18e0f6000c032db21e2d to your computer and use it in GitHub Desktop.
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