dry-mutations 0.99.2 → 0.99.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2737879381ea7e6b16728251b38259eb487a6ec3
4
- data.tar.gz: 678d954f5325839ee83665614039fa848ace4573
3
+ metadata.gz: 3ecccccba39df150e33413f46b687f0f0075e258
4
+ data.tar.gz: f622cf4b467f91d4ab5d77b8f9e781b312e60fd2
5
5
  SHA512:
6
- metadata.gz: f1c48b5bc25691331145a708e87e1745c091f17f5f6291a308eb491863433e7c5e410e55cf8d6dc19dedda46d8395f20a0e6497d9b5db720cf05b7422629ac7c
7
- data.tar.gz: 00c2063c2b10bcf5a29323aaa4b53e8d580920100ccdfd83ab65d8a3cc266ca4222abc894f56194c2ba5bdaf311da051230ca6a4ea2299a3bca9ee0ad8809502
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::Dummy
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! This is not yet implemented!**):
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. Such a block
169
- might be _only one_, and it _must be_ the first DSL in the mutation:
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 schema = nil, input_processor: nil, **options, &block
6
- @schema ||= patched_schema(schema) || derived_schema(input_processor: input_processor, **options, &block)
7
- return @schema unless block_given?
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
- @schema = Validation.Schema(@schema, **@schema.options, &Proc.new)
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
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '0.99.2'.freeze
3
+ VERSION = '0.99.9'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-mutations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.2
4
+ version: 0.99.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin