bcdd-result 0.9.0 → 0.9.1
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/CHANGELOG.md +18 -5
- data/README.md +2 -0
- data/lib/bcdd/result/context/failure.rb +1 -1
- data/lib/bcdd/result/context/success.rb +2 -2
- data/lib/bcdd/result/context.rb +7 -1
- data/lib/bcdd/result/version.rb +1 -1
- data/lib/bcdd/result.rb +14 -8
- data/sig/bcdd/result.rbs +6 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ccef0bd217127baf1bf96cabf4074c2ab2e8bb7befffd7c7f2f3df4631bf27
|
4
|
+
data.tar.gz: '0429c37305f2265dd13517c7a64e977929f6a4bde4b70421de01c8a418b67656'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8756ac806f830d458b3c830c15ac667cbb29f1737fa97cb59870541e2f3e8000839ab775c16559370499a7055db7f0938bb8a71071db9b5392507af5f0ec7de
|
7
|
+
data.tar.gz: 1003e299eec64ddb62a51b1f8d358b9dca2b58add3f8b4b9a4c46a5a70cb825907b2de7339c4f5e94817fb92e48c3a702eae67cd6eeca80942c60bdc80dff071
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
- [\[Unreleased\]](#unreleased)
|
2
|
+
- [\[0.9.1\] - 2023-12-12](#091---2023-12-12)
|
3
|
+
- [Changed](#changed)
|
4
|
+
- [Fixed](#fixed)
|
2
5
|
- [\[0.9.0\] - 2023-12-12](#090---2023-12-12)
|
3
6
|
- [Added](#added)
|
4
|
-
- [Changed](#changed)
|
7
|
+
- [Changed](#changed-1)
|
5
8
|
- [\[0.8.0\] - 2023-12-11](#080---2023-12-11)
|
6
9
|
- [Added](#added-1)
|
7
|
-
- [Changed](#changed-
|
10
|
+
- [Changed](#changed-2)
|
8
11
|
- [Removed](#removed)
|
9
12
|
- [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
|
10
13
|
- [Added](#added-2)
|
11
|
-
- [Changed](#changed-
|
14
|
+
- [Changed](#changed-3)
|
12
15
|
- [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
|
13
16
|
- [Added](#added-3)
|
14
|
-
- [Changed](#changed-
|
17
|
+
- [Changed](#changed-4)
|
15
18
|
- [\[0.5.0\] - 2023-10-09](#050---2023-10-09)
|
16
19
|
- [Added](#added-4)
|
17
20
|
- [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
|
18
21
|
- [Added](#added-5)
|
19
|
-
- [Changed](#changed-
|
22
|
+
- [Changed](#changed-5)
|
20
23
|
- [Removed](#removed-1)
|
21
24
|
- [\[0.3.0\] - 2023-09-26](#030---2023-09-26)
|
22
25
|
- [Added](#added-6)
|
@@ -28,6 +31,16 @@
|
|
28
31
|
|
29
32
|
## [Unreleased]
|
30
33
|
|
34
|
+
## [0.9.1] - 2023-12-12
|
35
|
+
|
36
|
+
### Changed
|
37
|
+
|
38
|
+
- **(BREAKING)** Make `BCDD::Result::Context::Success#and_expose()` to produce a halted success by default. You can turn this off by passing `halted: false`.
|
39
|
+
|
40
|
+
### Fixed
|
41
|
+
|
42
|
+
- Make `BCDD::Result::Context#and_then(&block)` accumulate the result value.
|
43
|
+
|
31
44
|
## [0.9.0] - 2023-12-12
|
32
45
|
|
33
46
|
### Added
|
data/README.md
CHANGED
@@ -1569,6 +1569,8 @@ Divide.new.call(10, 5)
|
|
1569
1569
|
#<BCDD::Result::Context::Success type=:ok value={:number=>2, :number1=>10, :number2=>5}>
|
1570
1570
|
```
|
1571
1571
|
|
1572
|
+
> PS: The `#and_expose` produces a halted success by default. This means the next step will not be executed even if you call `#and_then` after `#and_expose`. To change this behavior, you can pass `halted: false` to `#and_expose`.
|
1573
|
+
|
1572
1574
|
<p align="right"><a href="#-bcddresult">⬆️ back to top</a></p>
|
1573
1575
|
|
1574
1576
|
##### Module example (Singleton Methods)
|
@@ -3,13 +3,13 @@
|
|
3
3
|
class BCDD::Result::Context::Success < BCDD::Result::Context
|
4
4
|
include ::BCDD::Result::Success::Methods
|
5
5
|
|
6
|
-
def and_expose(type, keys)
|
6
|
+
def and_expose(type, keys, halted: true)
|
7
7
|
unless keys.is_a?(::Array) && !keys.empty? && keys.all?(::Symbol)
|
8
8
|
raise ::ArgumentError, 'keys must be an Array of Symbols'
|
9
9
|
end
|
10
10
|
|
11
11
|
exposed_value = acc.merge(value).slice(*keys)
|
12
12
|
|
13
|
-
self.class.new(type: type, value: exposed_value, subject: subject)
|
13
|
+
self.class.new(type: type, value: exposed_value, subject: subject, halted: halted)
|
14
14
|
end
|
15
15
|
end
|
data/lib/bcdd/result/context.rb
CHANGED
@@ -40,7 +40,7 @@ class BCDD::Result
|
|
40
40
|
-1
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def call_and_then_subject_method(method_name, context)
|
44
44
|
method = subject.method(method_name)
|
45
45
|
|
46
46
|
acc.merge!(value.merge(context))
|
@@ -55,6 +55,12 @@ class BCDD::Result
|
|
55
55
|
ensure_result_object(result, origin: :method)
|
56
56
|
end
|
57
57
|
|
58
|
+
def call_and_then_block(block)
|
59
|
+
acc.merge!(value)
|
60
|
+
|
61
|
+
call_and_then_block!(block, acc)
|
62
|
+
end
|
63
|
+
|
58
64
|
def ensure_result_object(result, origin:)
|
59
65
|
raise_unexpected_outcome_error(result, origin) unless result.is_a?(Context)
|
60
66
|
|
data/lib/bcdd/result/version.rb
CHANGED
data/lib/bcdd/result.rb
CHANGED
@@ -84,16 +84,12 @@ class BCDD::Result
|
|
84
84
|
tap { yield(value, type) if unknown }
|
85
85
|
end
|
86
86
|
|
87
|
-
def and_then(method_name = nil, context = nil)
|
87
|
+
def and_then(method_name = nil, context = nil, &block)
|
88
88
|
return self if halted?
|
89
89
|
|
90
|
-
method_name &&
|
90
|
+
method_name && block and raise ::ArgumentError, 'method_name and block are mutually exclusive'
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
result = yield(value)
|
95
|
-
|
96
|
-
ensure_result_object(result, origin: :block)
|
92
|
+
method_name ? call_and_then_subject_method(method_name, context) : call_and_then_block(block)
|
97
93
|
end
|
98
94
|
|
99
95
|
def handle
|
@@ -139,7 +135,7 @@ class BCDD::Result
|
|
139
135
|
block.call(value, type)
|
140
136
|
end
|
141
137
|
|
142
|
-
def
|
138
|
+
def call_and_then_subject_method(method_name, context)
|
143
139
|
method = subject.method(method_name)
|
144
140
|
|
145
141
|
result =
|
@@ -153,6 +149,16 @@ class BCDD::Result
|
|
153
149
|
ensure_result_object(result, origin: :method)
|
154
150
|
end
|
155
151
|
|
152
|
+
def call_and_then_block(block)
|
153
|
+
call_and_then_block!(block, value)
|
154
|
+
end
|
155
|
+
|
156
|
+
def call_and_then_block!(block, value)
|
157
|
+
result = block.call(value)
|
158
|
+
|
159
|
+
ensure_result_object(result, origin: :block)
|
160
|
+
end
|
161
|
+
|
156
162
|
def ensure_result_object(result, origin:)
|
157
163
|
raise Error::UnexpectedOutcome.build(outcome: result, origin: origin) unless result.is_a?(::BCDD::Result)
|
158
164
|
|
data/sig/bcdd/result.rbs
CHANGED
@@ -55,7 +55,9 @@ class BCDD::Result
|
|
55
55
|
|
56
56
|
def kind: -> Symbol
|
57
57
|
def known: (Proc) -> untyped
|
58
|
-
def
|
58
|
+
def call_and_then_subject_method: (Symbol, untyped) -> BCDD::Result
|
59
|
+
def call_and_then_block: (untyped) -> BCDD::Result
|
60
|
+
def call_and_then_block!: (untyped, untyped) -> BCDD::Result
|
59
61
|
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result
|
60
62
|
end
|
61
63
|
|
@@ -442,7 +444,7 @@ class BCDD::Result::Context < BCDD::Result
|
|
442
444
|
|
443
445
|
private
|
444
446
|
|
445
|
-
def
|
447
|
+
def call_and_then_subject_method: (Symbol, Hash[Symbol, untyped]) -> BCDD::Result::Context
|
446
448
|
def ensure_result_object: (untyped, origin: Symbol) -> BCDD::Result::Context
|
447
449
|
|
448
450
|
def raise_unexpected_outcome_error: (BCDD::Result::Context | untyped, Symbol) -> void
|
@@ -452,7 +454,7 @@ class BCDD::Result::Context
|
|
452
454
|
class Success < BCDD::Result::Context
|
453
455
|
include BCDD::Result::Success::Methods
|
454
456
|
|
455
|
-
def and_expose: (Symbol, Array[Symbol]) -> BCDD::Result::Context::Success
|
457
|
+
def and_expose: (Symbol, Array[Symbol], halted: bool) -> BCDD::Result::Context::Success
|
456
458
|
end
|
457
459
|
|
458
460
|
def self.Success: (Symbol, **untyped) -> BCDD::Result::Context::Success
|
@@ -462,7 +464,7 @@ class BCDD::Result::Context
|
|
462
464
|
class Failure < BCDD::Result::Context
|
463
465
|
include BCDD::Result::Failure::Methods
|
464
466
|
|
465
|
-
def and_expose: (Symbol, Array[Symbol]) -> BCDD::Result::Context::Failure
|
467
|
+
def and_expose: (Symbol, Array[Symbol], **untyped) -> BCDD::Result::Context::Failure
|
466
468
|
end
|
467
469
|
|
468
470
|
def self.Failure: (Symbol, **untyped) -> BCDD::Result::Context::Failure
|