Last active
October 22, 2019 13:29
-
-
Save Ptico/b8405ad7ffa2a3bea155ec46b813755a to your computer and use it in GitHub Desktop.
dry-schema partial
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
AddressSchema = Dry::Schema.Params do | |
required(:street).filled(:string) | |
required(:city).filled(:string) | |
required(:zipcode).filled(:string) | |
required(:email).filled(:string) | |
end | |
# ... | |
# CREATE { street: 'Baker Street', city: 'London', zipcode: 'NW1/W1', email: '[email protected]' } | |
post '/addresses' do | |
schema = AddressSchema.(params) | |
DB[:addresses].insert(schema.to_h) if schema.success? | |
end | |
# UPDATE { email: '[email protected]' } | |
patch '/address/:id' do | |
schema = AddressSchema.(params) # this will obviously fail | |
DB[:addresses].where(id: params['id']).update(schema.to_h) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment