dry-mutations 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +47 -1
- data/lib/dry/mutations/dsl/schema.rb +8 -1
- data/lib/dry/mutations/schema.rb +8 -7
- data/lib/dry/mutations/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9346b654bae4273294f8c7ee18f0fdd0c9d7be56
|
4
|
+
data.tar.gz: 578fb14621e715e8b3a36941d685295e36159fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1208949dedcb0550201668e796f544f757adfad8223c2c5b457938000ad82577d2ecf3abbf6a096278e996cbb7ba1ce123d5e3ebff377f4e707f13acbc2cc5c8
|
7
|
+
data.tar.gz: 7300929b9559be9476b5c4ffdb9f7d06e23dcc22c706d690c439470daf5b72889dec31bae64dcbe0d692002050bc6727c1333ceeaf14b0140ad6e227d6eaf4fc
|
data/README.md
CHANGED
@@ -162,7 +162,53 @@ required do
|
|
162
162
|
end
|
163
163
|
```
|
164
164
|
|
165
|
-
##
|
165
|
+
## Combining dry schemas with mutation-like syntax
|
166
|
+
|
167
|
+
Since version `0.11.1`, one might pass the instance of `Dry::Validation::Schema`
|
168
|
+
and/or `Dry::Validation::Form` instance to `schema` mutation DSL. Such a block
|
169
|
+
might be _only one_, and it _must be_ the first DSL in the mutation:
|
170
|
+
|
171
|
+
### Correct
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
Class.new(::Mutations::Command) do
|
175
|
+
prepend ::Dry::Mutations::Extensions::Command
|
176
|
+
prepend ::Dry::Mutations::Extensions::Sieve
|
177
|
+
|
178
|
+
schema(::Dry::Validation.Form do
|
179
|
+
required(:integer_value).filled(:int?, gt?: 0)
|
180
|
+
required(:date_value).filled(:date?)
|
181
|
+
required(:bool_value).filled(:bool?)
|
182
|
+
end)
|
183
|
+
|
184
|
+
required do
|
185
|
+
integer :forty_two
|
186
|
+
string :hello
|
187
|
+
end
|
188
|
+
end
|
189
|
+
```
|
190
|
+
|
191
|
+
### Incorrect
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
Class.new(::Mutations::Command) do
|
195
|
+
prepend ::Dry::Mutations::Extensions::Command
|
196
|
+
prepend ::Dry::Mutations::Extensions::Sieve
|
197
|
+
|
198
|
+
required do
|
199
|
+
integer :forty_two
|
200
|
+
string :hello
|
201
|
+
end
|
202
|
+
|
203
|
+
schema(::Dry::Validation.Form do
|
204
|
+
required(:integer_value).filled(:int?, gt?: 0)
|
205
|
+
required(:date_value).filled(:date?)
|
206
|
+
required(:bool_value).filled(:bool?)
|
207
|
+
end)
|
208
|
+
end
|
209
|
+
```
|
210
|
+
|
211
|
+
## Dealing with `outcome`
|
166
212
|
|
167
213
|
### Command
|
168
214
|
|
@@ -3,7 +3,7 @@ module Dry
|
|
3
3
|
module DSL # :nodoc:
|
4
4
|
module Schema # :nodoc:
|
5
5
|
def schema schema = nil, input_processor: nil, **options, &block
|
6
|
-
@schema ||= schema || derived_schema(input_processor: input_processor, **options, &block)
|
6
|
+
@schema ||= patched_schema(schema) || derived_schema(input_processor: input_processor, **options, &block)
|
7
7
|
return @schema unless block_given?
|
8
8
|
|
9
9
|
@schema = Validation.Schema(@schema, **@schema.options, &Proc.new)
|
@@ -25,6 +25,13 @@ module Dry
|
|
25
25
|
::Dry::Mutations.Schema(input_processor: input_processor, **options, &block)
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
def patched_schema(schema)
|
30
|
+
return nil unless schema.is_a?(::Dry::Validation::Schema)
|
31
|
+
schema.tap do |s|
|
32
|
+
s.config.instance_eval(&::Dry::Mutations::Schema::CONFIGURATOR)
|
33
|
+
end
|
34
|
+
end
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
data/lib/dry/mutations/schema.rb
CHANGED
@@ -4,17 +4,18 @@ module Dry
|
|
4
4
|
@@discarded = []
|
5
5
|
|
6
6
|
MESSAGES_FILE = (::File.join __dir__, '..', '..', '..', 'config', 'messages.yml').freeze
|
7
|
-
|
8
|
-
configure do |config|
|
7
|
+
CONFIGURATOR = ->(config) do
|
9
8
|
config.messages_file = MESSAGES_FILE
|
10
9
|
config.hash_type = :symbolized
|
11
|
-
config.input_processor = :sanitizer
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
predicates(::Dry::Mutations::Predicates)
|
10
|
+
config.input_processor = :sanitizer if config.input_processor == :noop
|
11
|
+
config.predicates = ::Dry::Mutations::Predicates
|
12
|
+
this = is_a?(::Dry::Validation::Schema) ? self : singleton_class
|
13
|
+
config.registry = ::Dry::Validation::PredicateRegistry[this, config.predicates]
|
16
14
|
end
|
17
15
|
|
16
|
+
configure(&CONFIGURATOR)
|
17
|
+
# predicates(::Dry::Mutations::Predicates)
|
18
|
+
|
18
19
|
def discarded
|
19
20
|
@@discarded
|
20
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-mutations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -390,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
390
390
|
version: '0'
|
391
391
|
requirements: []
|
392
392
|
rubyforge_project:
|
393
|
-
rubygems_version: 2.4.
|
393
|
+
rubygems_version: 2.4.6
|
394
394
|
signing_key:
|
395
395
|
specification_version: 4
|
396
396
|
summary: Mutations gem interface implemented with `dry-rb`’s validation schemas.
|