Skip to content

Instantly share code, notes, and snippets.

@CucumisSativus CucumisSativus/schema.rb Secret
Last active Aug 31, 2016

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