dry-mutations 0.99.0 → 0.99.1

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: 3283bff6b56af17bcf225925ddf1f408fa7b4c68
4
- data.tar.gz: a570341fa4d2a15633a09db13a7a5fe24129c273
3
+ metadata.gz: b84498f83aab334053ceadcf35a12ab919af5fdb
4
+ data.tar.gz: 508f7a5805a93949d189a6dfe06148f456a25562
5
5
  SHA512:
6
- metadata.gz: 228250b33066d8c6bac1b8a7319bbf95619243aa0a070b350faf6db34962df2926e3194d58e92f17c27c7932cea3d7fd15db8ca48056c9bdc28e53114de45499
7
- data.tar.gz: a6ffb1ffab92b3a109959806c2e1a2e70cdac4b85b9a46dea86bb934141c7eac04d3b855e9980b815a9b9c21b191db4be4c6d3d93ecb9dd77b1f103474ed236c
6
+ metadata.gz: 711ab39269cf47bfaee78acc30daff353dc274f1450b2746fac79fd4b3d7a186d7b0d1ae97c060f075231bfbcf8075ce5fab7b34070ed70b50d4fcb22537708b
7
+ data.tar.gz: 777c72b07f23f37659ec2aa788220122e940bb2bf5cad9fa81b82854312b8b56839ef4b3785ddc66d896a0095edd7f02b411befdfa84864e406ffc44cc5cea12
data/README.md CHANGED
@@ -112,7 +112,7 @@ class MyMutation < Mutations::Command
112
112
  string :maturity_choice, in: %w(spot forward_days fixed_date)
113
113
  optional do
114
114
  hash :maturity_days_set do
115
- integer :days # For spot or forward_days options
115
+ integer :days, default: 3 # For spot or forward_days options
116
116
  end
117
117
  hash :maturity_date_set do
118
118
  date :date # When passing a fixed date
@@ -284,6 +284,20 @@ new functionality. This is untested in all possible environments.
284
284
 
285
285
  Bug reports are very welcome!
286
286
 
287
+ ## Changelog
288
+
289
+ #### 0.99.1
290
+ Support for direct input parameters invocation. 100%-compatibility with `mutations`:
291
+
292
+ ```ruby
293
+ def validate # input ≡ { date: nil }
294
+ date < Date.now
295
+ end
296
+ ```
297
+
298
+ #### 0.99.0
299
+ Support for `default:` guard. 99%-compatibility with `mutations`
300
+
287
301
  ## Development
288
302
 
289
303
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -39,7 +39,7 @@ module Dry
39
39
 
40
40
  @validation_result = discard_empty!
41
41
 
42
- @inputs = Utils.Hash @validation_result.output
42
+ @inputs = fix_accessors Utils.Hash @validation_result.output
43
43
 
44
44
  # dry: {:name=>["size cannot be greater than 10"],
45
45
  # :properties=>{:first_arg=>["must be a string", "is in invalid format"]},
@@ -163,6 +163,24 @@ module Dry
163
163
  end.compact.to_h
164
164
  )
165
165
  end
166
+
167
+ def fix_accessors hash
168
+ hash.each do |method, _|
169
+ next if respond_to?(name = method)
170
+
171
+ singleton_class.tap do |c|
172
+ c.send(:define_method, name) { @inputs[name] }
173
+ if c < Enumerable
174
+ c.send(:define_method, :"#{name}_present?") do
175
+ @inputs.key?(name) && !@inputs[name].empty?
176
+ end
177
+ else
178
+ c.send(:define_method, :"#{name}_present?") { @inputs.key?(name) }
179
+ c.send(:define_method, :"#{name}=") { |value| @inputs[name] = value }
180
+ end
181
+ end
182
+ end
183
+ end
166
184
  end
167
185
  end
168
186
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '0.99.0'.freeze
3
+ VERSION = '0.99.1'.freeze
4
4
  end
5
5
  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.99.0
4
+ version: 0.99.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-12-15 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler