dry-mutations 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dry/mutations/extensions/command.rb +14 -1
- data/lib/dry/mutations/extensions/outcome.rb +9 -3
- data/lib/dry/mutations/transactions/step_adapters.rb +8 -0
- data/lib/dry/mutations/transactions/step_adapters/tranquilo.rb +0 -4
- data/lib/dry/mutations/utils/generic.rb +11 -0
- data/lib/dry/mutations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b5e7decfb90e826930fba23b09132cf888b044
|
4
|
+
data.tar.gz: f08c0296e1f5fff04ee3beb5d37546582a603baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd5b5f254adc9285bfd52ce62422038c8f8f76f3735e431f9a5abd328479700c98c37618040960d29fbd6fdc3aab819342d64c789155a98fb86b0e7a9bbbc87c
|
7
|
+
data.tar.gz: 3dd1490a0226e6f2fc70fdb5154adfb16c8181d3ba76eacb58fbbc897df50d7352ed2d98c3b1a7390a8d1c33ad160871a882f2d26c5d3b675a80ee1b1c564f19
|
data/Gemfile.lock
CHANGED
@@ -17,7 +17,10 @@ module Dry
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def call(*args)
|
20
|
-
|
20
|
+
callable = to_proc.(*args)
|
21
|
+
outcome = callable.()
|
22
|
+
ensure
|
23
|
+
::Dry::Mutations::Utils.extend_outcome outcome, callable.host
|
21
24
|
end
|
22
25
|
|
23
26
|
def to_proc
|
@@ -38,6 +41,10 @@ module Dry
|
|
38
41
|
%i|exceptions_as_errors finalizers call to_proc|.include?(method_name) || super
|
39
42
|
end
|
40
43
|
end)
|
44
|
+
|
45
|
+
define_method :host do
|
46
|
+
base.to_s
|
47
|
+
end
|
41
48
|
end
|
42
49
|
|
43
50
|
attr_reader :validation
|
@@ -72,6 +79,12 @@ module Dry
|
|
72
79
|
### Functional helpers
|
73
80
|
########################################################################
|
74
81
|
|
82
|
+
def run
|
83
|
+
outcome = super
|
84
|
+
ensure
|
85
|
+
::Dry::Mutations::Utils.extend_outcome outcome, host
|
86
|
+
end
|
87
|
+
|
75
88
|
def call
|
76
89
|
run.either
|
77
90
|
end
|
@@ -91,11 +91,17 @@ module Dry
|
|
91
91
|
case input
|
92
92
|
when ::Mutations::Outcome then input
|
93
93
|
when ::Dry::Monads::Either::Left
|
94
|
-
::Mutations::Outcome.new(false, nil, input.value, nil)
|
94
|
+
::Mutations::Outcome.new(false, nil, input.value, nil).tap do |outcome|
|
95
|
+
::Dry::Mutations::Utils.extend_outcome outcome, input.value.host
|
96
|
+
end
|
95
97
|
when ::Dry::Monads::Either::Right
|
96
|
-
::Mutations::Outcome.new(true, input.value, nil, nil)
|
98
|
+
::Mutations::Outcome.new(true, input.value, nil, nil).tap do |outcome|
|
99
|
+
::Dry::Mutations::Utils.extend_outcome outcome, input.value.host
|
100
|
+
end
|
97
101
|
when ->(inp) { inp.respond_to?(:success?) }
|
98
|
-
::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil)
|
102
|
+
::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil).tap do |outcome|
|
103
|
+
::Dry::Mutations::Utils.extend_outcome outcome, input.host if input.respond_to?(:host)
|
104
|
+
end
|
99
105
|
else fail TypeError.new("Wrong input passed to Outcome(): [#{input.inspect}]")
|
100
106
|
end
|
101
107
|
end
|
@@ -10,6 +10,14 @@ module Dry
|
|
10
10
|
name = Utils.Snake(sub, short: true, symbolize: true)
|
11
11
|
StepAdapters.register name, sub.new
|
12
12
|
adapters[name] = sub
|
13
|
+
|
14
|
+
sub.prepend(Module.new do
|
15
|
+
def call(step, *args, input)
|
16
|
+
outcome = super
|
17
|
+
ensure
|
18
|
+
::Dry::Mutations::Utils.extend_outcome outcome.value, "#{step.step_name}::#{step.operation_name}"
|
19
|
+
end
|
20
|
+
end)
|
13
21
|
end
|
14
22
|
|
15
23
|
def self.adapters
|
@@ -5,10 +5,6 @@ module Dry
|
|
5
5
|
# step adapters must provide a single `#call(step, *args, input)` method,
|
6
6
|
# which should return the step’s result wrapped in an `Either` object.
|
7
7
|
class Tranquilo < StepAdapters::Move # :nodoc:
|
8
|
-
def call(step, *args, input)
|
9
|
-
# TODO: FIXME: PENDING: when block passing is merged into dry-validation
|
10
|
-
step.operation.(input, *args)
|
11
|
-
end
|
12
8
|
end
|
13
9
|
end
|
14
10
|
end
|
@@ -55,6 +55,17 @@ module Dry
|
|
55
55
|
end
|
56
56
|
|
57
57
|
ITSELF = ->(h, k) { h[k] = k }
|
58
|
+
|
59
|
+
def self.extend_outcome(whatever, host)
|
60
|
+
whatever.tap do |outcome|
|
61
|
+
outcome.instance_variable_set(:@host, host)
|
62
|
+
outcome.extend(Module.new do
|
63
|
+
def host
|
64
|
+
@host
|
65
|
+
end
|
66
|
+
end)
|
67
|
+
end
|
68
|
+
end
|
58
69
|
end
|
59
70
|
end
|
60
71
|
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: 1.5.
|
4
|
+
version: 1.5.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: 2017-06-
|
11
|
+
date: 2017-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|