Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Processor#merge which allows merging schemas #256

Merged
merged 1 commit into from
Mar 4, 2020
Merged

Conversation

solnic
Copy link
Member

@solnic solnic commented Mar 4, 2020

Refs dry-rb/dry-validation#593

This adds merge interface to all schema types. It allows merging two schemas into a new schema that will include all rules from both schemas as well as their types, steps and parents.

require 'dry/schema'

s1 = Dry::Schema.define do
  required(:name).filled(:string)
end

s2 = Dry::Schema.define do
  required(:age).value(:integer)
end

schema = s1.merge(s2)

puts schema.(name: '', age: 'foo').errors.to_h.inspect
# {:name=>["must be filled"], :age=>["must be an integer"]}

@solnic solnic requested a review from flash-gordon March 4, 2020 09:23
@solnic solnic merged commit 56a1bdb into master Mar 4, 2020
@solnic solnic deleted the merging-schemas branch March 4, 2020 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants