dry-mutations 0.8.93 → 0.8.95
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dry/mutations/extensions/outcome.rb +10 -2
- 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: ab34cce7ae7dae0a65fb5c0deae32a5b58d80b4d
|
4
|
+
data.tar.gz: 807b22566a844bded55c9fbf8f3cde5f02e6926f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9bf7564f9c36b9bb5b4219355f142c688813663936d1d2dfd123e56045b525c90faab9876fbad350e88c27c53966e51dc14ddc5487b4ae1ef41d26a93f0c7d1
|
7
|
+
data.tar.gz: c2f1299819df0f7bcce26cf41c718e03447e12a0e034d49cc39538225537cbefce6c8e844529e1faff5bf99f1945132bc342f1b7372e6cab50c42c3a9911b4af
|
@@ -10,8 +10,9 @@ module Dry
|
|
10
10
|
attr_reader :outcome, :either
|
11
11
|
|
12
12
|
def initialize(outcome)
|
13
|
+
@∨ = outcome.class.instance_variable_get(:@∨)
|
13
14
|
@either = Right(@outcome = outcome).bind do |value|
|
14
|
-
value.success
|
15
|
+
value.public_send(@∨[:success]) ? Right(value.public_send(@∨[:right])) : Left(value.public_send(@∨[:left]))
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -41,8 +42,15 @@ module Dry
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def self.prepended base
|
44
|
-
|
45
|
+
λ = base.instance_methods.method(:include?)
|
46
|
+
base.instance_variable_set(:@∨, {
|
47
|
+
left: [:errors, :left].detect(&λ),
|
48
|
+
right: [:result, :output, :right].detect(&λ),
|
49
|
+
success: [:success?].detect(&λ)
|
50
|
+
}.reject { |_, v| v.nil? }.merge(base.instance_variable_get(:@∨) || {}))
|
51
|
+
fail ArgumentError, "Can not have #{self} #{__callee__} to #{base}: base class must look like an either." unless base.instance_variable_get(:@∨).size == 3
|
45
52
|
end
|
53
|
+
singleton_class.send :alias_method, :included, :prepended
|
46
54
|
|
47
55
|
def either
|
48
56
|
@either ||= EitherCalculator.new(self).either
|