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 +4 -4
- data/lib/dry/mutations/extensions/outcome.rb +6 -0
- data/lib/dry/mutations/transactions/dsl.rb +11 -0
- data/lib/dry/mutations/utils.rb +10 -1
- 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: 2fa4bc02fc1806cb613a3d803cca96da5451905b
|
4
|
+
data.tar.gz: 81c2ba3bfcbf356fbe4fe85b3260fdfa388f969d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/dry/mutations/utils.rb
CHANGED
@@ -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 '
|
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
|