dry-mutations 0.8.12 → 0.8.13
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 037fef1da0d822b477b53b0d2e5cbbc68739148e
|
4
|
+
data.tar.gz: ca900597fee286845d886cd93d7d9041460f4dc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0b5855b30691cf2e22968ea246c6a810c90573388451893ccb6ed1f558b30531aae0f0176ae53256266fc02f7c75759291340b84e8d9bacc5e5050a4edd8dc
|
7
|
+
data.tar.gz: d8cabef109dda5d57dec635890fc333c2e1871926fafe6731b6110b262fcfc1e98988ed12ebfcb6db16f4a2694d2de47bbb9af1e8ed0417630ced6974fe2d2b1
|
@@ -75,13 +75,7 @@ module Dry
|
|
75
75
|
########################################################################
|
76
76
|
|
77
77
|
def validation_outcome(result = nil)
|
78
|
-
|
79
|
-
super.tap do |outcome|
|
80
|
-
outcome.singleton_class.tap do |klazz|
|
81
|
-
klazz.prepend Outcome unless klazz.ancestors.include?(Outcome)
|
82
|
-
end
|
83
|
-
outcome.eitherify!
|
84
|
-
end
|
78
|
+
::Dry::Mutations::Extensions::Outcome(super)
|
85
79
|
end
|
86
80
|
|
87
81
|
def execute
|
@@ -7,10 +7,10 @@ module Dry
|
|
7
7
|
class EitherCalculator # :nodoc:
|
8
8
|
include Dry::Monads::Either::Mixin
|
9
9
|
|
10
|
-
|
10
|
+
attr_reader :outcome, :either
|
11
11
|
|
12
|
-
def
|
13
|
-
Right(outcome).bind do |value|
|
12
|
+
def initialize(outcome)
|
13
|
+
@either = Right(@outcome = outcome).bind do |value|
|
14
14
|
value.success? ? Right(value.result) : Left(value.errors)
|
15
15
|
end
|
16
16
|
end
|
@@ -41,32 +41,23 @@ module Dry
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.prepended base
|
44
|
-
fail ArgumentError, "Can not prepend #{self
|
44
|
+
fail ArgumentError, "Can not prepend #{self} to #{base}: base class must be a ::Mutations::Outcome descendant." unless base <= ::Mutations::Outcome
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
def initialize(is_success, result, errors, inputs)
|
50
|
-
super is_success, result, errors, inputs
|
51
|
-
etherify!
|
52
|
-
end
|
53
|
-
|
54
|
-
def eitherify!
|
55
|
-
calc = EitherCalculator.new
|
56
|
-
calc.outcome = self
|
57
|
-
@either = calc.calculate
|
47
|
+
def either
|
48
|
+
@either ||= EitherCalculator.new(self).either
|
58
49
|
end
|
59
50
|
|
60
51
|
def right?
|
61
|
-
|
52
|
+
either.is_a?(Right)
|
62
53
|
end
|
63
54
|
|
64
55
|
def left?
|
65
|
-
|
56
|
+
either.is_a?(Left)
|
66
57
|
end
|
67
58
|
|
68
59
|
def value
|
69
|
-
|
60
|
+
either.value
|
70
61
|
end
|
71
62
|
|
72
63
|
def match
|
@@ -74,6 +65,21 @@ module Dry
|
|
74
65
|
Matcher.!.(self, &Proc.new)
|
75
66
|
end
|
76
67
|
end
|
68
|
+
|
69
|
+
::Mutations::Outcome.prepend Outcome unless ::Mutations::Outcome.ancestors.include?(Outcome)
|
70
|
+
|
71
|
+
def self.Outcome input
|
72
|
+
case input
|
73
|
+
when ::Mutations::Outcome then input
|
74
|
+
when ::Dry::Monads::Either::Left
|
75
|
+
::Mutations::Outcome.new(false, nil, input.value, nil)
|
76
|
+
when ::Dry::Monads::Either::Right
|
77
|
+
::Mutations::Outcome.new(true, input.value, nil, nil)
|
78
|
+
when ->(inp) { inp.respond_to?(:success?) }
|
79
|
+
::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil)
|
80
|
+
else fail TypeError.new("Wrong input passed to Outcome(): [#{input.inspect}]")
|
81
|
+
end
|
82
|
+
end
|
77
83
|
end
|
78
84
|
end
|
79
85
|
end
|
@@ -25,7 +25,9 @@ module Dry
|
|
25
25
|
singleton_class.send :define_method, :call do |input|
|
26
26
|
transaction.(input)
|
27
27
|
end
|
28
|
-
singleton_class.send
|
28
|
+
singleton_class.send :define_method, :run do |input|
|
29
|
+
::Dry::Mutations::Extensions::Outcome(transaction.(input))
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
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.8.
|
4
|
+
version: 0.8.13
|
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-07-
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|