dry-mutations 0.8.13 → 0.8.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 037fef1da0d822b477b53b0d2e5cbbc68739148e
4
- data.tar.gz: ca900597fee286845d886cd93d7d9041460f4dc7
3
+ metadata.gz: 2fa4bc02fc1806cb613a3d803cca96da5451905b
4
+ data.tar.gz: 81c2ba3bfcbf356fbe4fe85b3260fdfa388f969d
5
5
  SHA512:
6
- metadata.gz: dd0b5855b30691cf2e22968ea246c6a810c90573388451893ccb6ed1f558b30531aae0f0176ae53256266fc02f7c75759291340b84e8d9bacc5e5050a4edd8dc
7
- data.tar.gz: d8cabef109dda5d57dec635890fc333c2e1871926fafe6731b6110b262fcfc1e98988ed12ebfcb6db16f4a2694d2de47bbb9af1e8ed0417630ced6974fe2d2b1
6
+ metadata.gz: f70755498be311d9acf031838b70d24e151a27f52367fa567e3e4d067590ed5c0963700568cc25b94f6d6cca7f09829998ff93055cdf9037baa8781602623c48
7
+ data.tar.gz: db1fa05b824b4662c5cd36eaa63bf0a1a8541c2fbb59a6766d8f2d3602af50c572233ea27769b85e8593fdee892d4ab1ea41d966cf32da067eda5bd62d338daa
@@ -80,6 +80,12 @@ module Dry
80
80
  else fail TypeError.new("Wrong input passed to Outcome(): [#{input.inspect}]")
81
81
  end
82
82
  end
83
+
84
+ def self.Outcome! input
85
+ outcome = Outcome(input)
86
+ raise ::Mutations::ValidationException.new(outcome.errors) unless outcome.success?
87
+ outcome.value
88
+ end
83
89
  end
84
90
  end
85
91
  end
@@ -12,6 +12,14 @@ module Dry
12
12
 
13
13
  def self.extended base
14
14
  fail Errors::TypeError.new("Extended class [#{base}] should not respond to :call, it is defined by this extension.") if base.respond_to?(:call)
15
+ base.send :define_method, :initialize do |input|
16
+ @input = input
17
+ end unless base.instance_methods(false).include?(:initialize)
18
+ %i(run run!).each do |meth|
19
+ base.send :define_method, meth do
20
+ base.public_send(meth, @input)
21
+ end unless base.instance_methods(false).include?(meth)
22
+ end
15
23
  end
16
24
 
17
25
  def chain **params
@@ -28,6 +36,9 @@ module Dry
28
36
  singleton_class.send :define_method, :run do |input|
29
37
  ::Dry::Mutations::Extensions::Outcome(transaction.(input))
30
38
  end
39
+ singleton_class.send :define_method, :run! do |input|
40
+ ::Dry::Mutations::Extensions::Outcome!(transaction.(input))
41
+ end
31
42
  end
32
43
  end
33
44
  end
@@ -116,7 +116,16 @@ module Dry
116
116
  ::Dry::Types['strict.string'], fn: ->(v) { v.to_s.strip }
117
117
  )
118
118
  end
119
- when 'integer' then :int?
119
+ when 'date'
120
+ ::Dry::Types::Constructor.new(
121
+ ::Dry::Types['strict.date'], fn: ->(v) { v.is_a?(Date) ? v : (Date.parse(v.to_s) rescue v) }
122
+ )
123
+ when 'integer'
124
+ :int?
125
+ # FIXME: Why ints are not coercible?!
126
+ #::Dry::Types::Constructor.new(
127
+ # ::Dry::Types['coercible.int'], fn: ->(v) { v.is_a?(Integer) ? v : (v.to_i rescue v) }
128
+ #)
120
129
  when 'boolean' then :bool?
121
130
  else :"#{type}?"
122
131
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '0.8.13'.freeze
3
+ VERSION = '0.8.14'.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.8.13
4
+ version: 0.8.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin