dry-mutations 0.99.2 → 0.99.9
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 +21 -5
- data/lib/dry/mutations/dsl/schema.rb +16 -4
- data/lib/dry/mutations/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ecccccba39df150e33413f46b687f0f0075e258
|
4
|
+
data.tar.gz: f622cf4b467f91d4ab5d77b8f9e781b312e60fd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4abbb1d1856b4086ec31be72f25c804409bd9aa47dcc579bd901a1eefb6831e911052d112f7acabadecf13e93fd2629afb5569543b008e097bc176bb1703037
|
7
|
+
data.tar.gz: 373f196cc267a68a6d63470f7fcbf84c3d70724f51f847c3cacd479fa91c43b2378a8d17847e87840f11428c6d164482330768878ac00c7e7c246242dd05e613
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ end
|
|
53
53
|
```ruby
|
54
54
|
class ComposedValidation < Mutations::Command
|
55
55
|
prepend ::Dry::Mutations::Extensions::Command
|
56
|
-
prepend ::Dry::Mutations::Extensions::
|
56
|
+
prepend ::Dry::Mutations::Extensions::Sieve
|
57
57
|
|
58
58
|
...
|
59
59
|
def validate
|
@@ -152,21 +152,37 @@ UserSchema = Dry::Validation.Schema do
|
|
152
152
|
end
|
153
153
|
```
|
154
154
|
|
155
|
-
or, in legacy `mutations` syntax (**NB!
|
155
|
+
or, in legacy `mutations` syntax (**NB! Starting with `0.99.9`!**):
|
156
156
|
|
157
157
|
```ruby
|
158
158
|
required do
|
159
|
-
string :email
|
160
159
|
string :name
|
161
160
|
schema :address, AddressSchema
|
161
|
+
string :email
|
162
162
|
end
|
163
163
|
```
|
164
164
|
|
165
165
|
## Combining dry schemas with mutation-like syntax
|
166
166
|
|
167
|
+
Since version `0.99.9`, one might pass the `Dry::Validation::Schema` directly
|
168
|
+
to legacy mutations syntax:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
required do
|
172
|
+
model :user
|
173
|
+
schema :address, AddressSchema # AddressSchema = ::Dry::Validation.Schema {}
|
174
|
+
date: Date.today
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
---
|
179
|
+
|
167
180
|
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.
|
169
|
-
|
181
|
+
and/or `Dry::Validation::Form` instance to `schema` mutation DSL.
|
182
|
+
|
183
|
+
Such a block might be _only one_, and it _must be_ the first DSL in the mutation.
|
184
|
+
**NB** this is not a preferred way to do things, but it might be useful to _share_
|
185
|
+
schemas (unlikely the above, this will _embed_ the schema, rather than _nest_ it.)
|
170
186
|
|
171
187
|
### Correct
|
172
188
|
|
@@ -2,11 +2,23 @@ module Dry
|
|
2
2
|
module Mutations
|
3
3
|
module DSL # :nodoc:
|
4
4
|
module Schema # :nodoc:
|
5
|
-
def schema
|
6
|
-
|
7
|
-
|
5
|
+
def schema *args, input_processor: nil, **options, &block
|
6
|
+
case args.count
|
7
|
+
when 0, 1
|
8
|
+
schema, = args
|
9
|
+
@schema ||= patched_schema(schema) || derived_schema(input_processor: input_processor, **options, &block)
|
10
|
+
return @schema unless block_given?
|
8
11
|
|
9
|
-
|
12
|
+
@schema = Validation.Schema(@schema, **@schema.options, &Proc.new)
|
13
|
+
when 2 # explicit dry schema given
|
14
|
+
name = args.first
|
15
|
+
current = @current # closure scope
|
16
|
+
|
17
|
+
schema do
|
18
|
+
Utils.smart_send(__send__(current, name), :schema, args.last, **options, &block)
|
19
|
+
end
|
20
|
+
define_method(name) { Utils::Hash(@inputs[name]) }
|
21
|
+
end
|
10
22
|
end
|
11
23
|
|
12
24
|
private
|