bcdd-result 1.0.0 → 1.1.0
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 +25 -14
- data/README.md +17 -8
- data/lib/bcdd/context/callable_and_then.rb +1 -1
- data/lib/bcdd/context/success.rb +5 -5
- data/lib/bcdd/context.rb +34 -10
- data/lib/bcdd/result/version.rb +1 -1
- data/sig/bcdd/context.rbs +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 65c4eca57e46f7c344320d812e2bf95d4ca6e1779fe03d3f0903baf747998f4c
|
|
4
|
+
data.tar.gz: ca668bce32035b2dacf6d4b5cde769b3da0302ebb005ae6d920267b79b4e1777
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 659e109cbf9782ea83b351d775b4d854d40769cefc5193590cc45fcd2b4857e8b321fb92be479ab5ecff0affcc765c2d8ddafabcc8a57fad6f2a7f5c4be5f9c5
|
|
7
|
+
data.tar.gz: 047f861d008d7f4831d3b351c7162e4eda9108febad3ae425a14dbe9e092502010de44d56854f9c04e3c61a470ba6f6fc7ff1931a0ac8952460930b7e650f637
|
data/CHANGELOG.md
CHANGED
|
@@ -1,50 +1,61 @@
|
|
|
1
1
|
- [\[Unreleased\]](#unreleased)
|
|
2
|
-
- [1.
|
|
2
|
+
- [1.1.0 - 2024-03-25](#110---2024-03-25)
|
|
3
3
|
- [Added](#added)
|
|
4
|
+
- [1.0.0 - 2024-03-16](#100---2024-03-16)
|
|
5
|
+
- [Added](#added-1)
|
|
4
6
|
- [Changed](#changed)
|
|
5
7
|
- [\[0.13.0\] - 2024-02-01](#0130---2024-02-01)
|
|
6
|
-
- [Added](#added-
|
|
8
|
+
- [Added](#added-2)
|
|
7
9
|
- [Changed](#changed-1)
|
|
8
10
|
- [\[0.12.0\] - 2024-01-07](#0120---2024-01-07)
|
|
9
|
-
- [Added](#added-
|
|
11
|
+
- [Added](#added-3)
|
|
10
12
|
- [Changed](#changed-2)
|
|
11
13
|
- [\[0.11.0\] - 2024-01-02](#0110---2024-01-02)
|
|
12
|
-
- [Added](#added-
|
|
14
|
+
- [Added](#added-4)
|
|
13
15
|
- [Changed](#changed-3)
|
|
14
16
|
- [\[0.10.0\] - 2023-12-31](#0100---2023-12-31)
|
|
15
|
-
- [Added](#added-
|
|
17
|
+
- [Added](#added-5)
|
|
16
18
|
- [\[0.9.1\] - 2023-12-12](#091---2023-12-12)
|
|
17
19
|
- [Changed](#changed-4)
|
|
18
20
|
- [Fixed](#fixed)
|
|
19
21
|
- [\[0.9.0\] - 2023-12-12](#090---2023-12-12)
|
|
20
|
-
- [Added](#added-
|
|
22
|
+
- [Added](#added-6)
|
|
21
23
|
- [Changed](#changed-5)
|
|
22
24
|
- [\[0.8.0\] - 2023-12-11](#080---2023-12-11)
|
|
23
|
-
- [Added](#added-
|
|
25
|
+
- [Added](#added-7)
|
|
24
26
|
- [Changed](#changed-6)
|
|
25
27
|
- [Removed](#removed)
|
|
26
28
|
- [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
|
|
27
|
-
- [Added](#added-
|
|
29
|
+
- [Added](#added-8)
|
|
28
30
|
- [Changed](#changed-7)
|
|
29
31
|
- [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
|
|
30
|
-
- [Added](#added-
|
|
32
|
+
- [Added](#added-9)
|
|
31
33
|
- [Changed](#changed-8)
|
|
32
34
|
- [\[0.5.0\] - 2023-10-09](#050---2023-10-09)
|
|
33
|
-
- [Added](#added-9)
|
|
34
|
-
- [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
|
|
35
35
|
- [Added](#added-10)
|
|
36
|
+
- [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
|
|
37
|
+
- [Added](#added-11)
|
|
36
38
|
- [Changed](#changed-9)
|
|
37
39
|
- [Removed](#removed-1)
|
|
38
40
|
- [\[0.3.0\] - 2023-09-26](#030---2023-09-26)
|
|
39
|
-
- [Added](#added-11)
|
|
40
|
-
- [\[0.2.0\] - 2023-09-26](#020---2023-09-26)
|
|
41
41
|
- [Added](#added-12)
|
|
42
|
+
- [\[0.2.0\] - 2023-09-26](#020---2023-09-26)
|
|
43
|
+
- [Added](#added-13)
|
|
42
44
|
- [Removed](#removed-2)
|
|
43
45
|
- [\[0.1.0\] - 2023-09-25](#010---2023-09-25)
|
|
44
|
-
- [Added](#added-
|
|
46
|
+
- [Added](#added-14)
|
|
45
47
|
|
|
46
48
|
## [Unreleased]
|
|
47
49
|
|
|
50
|
+
## 1.1.0 - 2024-03-25
|
|
51
|
+
|
|
52
|
+
### Added
|
|
53
|
+
|
|
54
|
+
- Add some Hash's methods to `BCDD::Context`. They are:
|
|
55
|
+
- `#slice` to extract only the desired keys.
|
|
56
|
+
- `#[]`, `#dig`, `#fetch` to access the values.
|
|
57
|
+
- `#values_at` and `#fetch_values` to get the values of the desired keys.
|
|
58
|
+
|
|
48
59
|
## 1.0.0 - 2024-03-16
|
|
49
60
|
|
|
50
61
|
### Added
|
data/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Use it to enable the [Railway Oriented Programming](https://fsharpforfunandprofi
|
|
|
63
63
|
- [`BCDD::Result::Expectations.mixin` add-ons](#bcddresultexpectationsmixin-add-ons)
|
|
64
64
|
- [`BCDD::Context`](#bcddcontext)
|
|
65
65
|
- [Defining successes and failures](#defining-successes-and-failures)
|
|
66
|
-
- [
|
|
66
|
+
- [Hash methods](#hash-methods)
|
|
67
67
|
- [`BCDD::Context.mixin`](#bcddcontextmixin)
|
|
68
68
|
- [Class example (Instance Methods)](#class-example-instance-methods-1)
|
|
69
69
|
- [`and_expose`](#and_expose)
|
|
@@ -1436,20 +1436,29 @@ BCDD::Context::Success(:ok, **{ message: 'hashes can be converted to keyword arg
|
|
|
1436
1436
|
|
|
1437
1437
|
<p align="right"><a href="#-bcddresult">⬆️ back to top</a></p>
|
|
1438
1438
|
|
|
1439
|
-
####
|
|
1439
|
+
#### Hash methods
|
|
1440
1440
|
|
|
1441
|
-
|
|
1441
|
+
The `BCDD::Context` only accepts hashes as its values. Because of this, its instances have some Hash's methods to query/access the values. The available methods are:
|
|
1442
|
+
|
|
1443
|
+
- `#slice` to extract only the desired keys.
|
|
1444
|
+
- `#[]`, `#dig`, `#fetch` to access the values.
|
|
1445
|
+
- `#values_at` and `#fetch_values` to get the values of the desired keys.
|
|
1442
1446
|
|
|
1443
1447
|
```ruby
|
|
1444
|
-
BCDD::
|
|
1445
|
-
config.context_alias.enable!('BCDD::Context')
|
|
1448
|
+
result = BCDD::Context::Success(:ok, a: 1, b: 2, c: {d: 4})
|
|
1446
1449
|
|
|
1447
|
-
|
|
1450
|
+
result[:a] # 1
|
|
1451
|
+
result.fetch(:a) # 1
|
|
1452
|
+
result.dig(:c, :d) # 4
|
|
1448
1453
|
|
|
1449
|
-
|
|
1450
|
-
|
|
1454
|
+
result.slice(:a, :b) # {:a=>1, :b=>2}
|
|
1455
|
+
|
|
1456
|
+
result.values_at(:a, :b) # [1, 2]
|
|
1457
|
+
result.fetch_values(:a, :b) # [1, 2]
|
|
1451
1458
|
```
|
|
1452
1459
|
|
|
1460
|
+
These methods are available for `BCDD::Context::Success` and `BCDD::Context::Failure` instances.
|
|
1461
|
+
|
|
1453
1462
|
<p align="right"><a href="#-bcddresult">⬆️ back to top</a></p>
|
|
1454
1463
|
|
|
1455
1464
|
#### `BCDD::Context.mixin`
|
|
@@ -28,7 +28,7 @@ module BCDD
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def self.ensure_result_object(source, value, result)
|
|
31
|
-
return result.tap { result.send(:
|
|
31
|
+
return result.tap { result.send(:memo).then { _1.merge!(value.merge(_1)) } } if result.is_a?(Context)
|
|
32
32
|
|
|
33
33
|
raise Result::Error::UnexpectedOutcome.build(outcome: result, origin: source,
|
|
34
34
|
expected: Context::EXPECTED_OUTCOME)
|
data/lib/bcdd/context/success.rb
CHANGED
|
@@ -8,12 +8,12 @@ class BCDD::Context
|
|
|
8
8
|
class Success < self
|
|
9
9
|
include ::BCDD::Success
|
|
10
10
|
|
|
11
|
-
FetchValues = ->(
|
|
12
|
-
fetched_values =
|
|
11
|
+
FetchValues = ->(memo_values, keys) do
|
|
12
|
+
fetched_values = memo_values.fetch_values(*keys)
|
|
13
13
|
|
|
14
14
|
keys.zip(fetched_values).to_h
|
|
15
15
|
rescue ::KeyError => e
|
|
16
|
-
message = "#{e.message}. Available to expose: #{
|
|
16
|
+
message = "#{e.message}. Available to expose: #{memo_values.keys.map(&:inspect).join(', ')}"
|
|
17
17
|
|
|
18
18
|
raise Error::InvalidExposure, message
|
|
19
19
|
end
|
|
@@ -25,9 +25,9 @@ class BCDD::Context
|
|
|
25
25
|
|
|
26
26
|
EventLogs.tracking.reset_and_then!
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
memo_values = memo.merge(value)
|
|
29
29
|
|
|
30
|
-
value_to_expose = FetchValues.call(
|
|
30
|
+
value_to_expose = FetchValues.call(memo_values, keys)
|
|
31
31
|
|
|
32
32
|
expectations = type_checker.expectations
|
|
33
33
|
|
data/lib/bcdd/context.rb
CHANGED
|
@@ -20,7 +20,7 @@ class BCDD::Context < BCDD::Result
|
|
|
20
20
|
def initialize(type:, value:, source: nil, expectations: nil, terminal: nil)
|
|
21
21
|
value.is_a?(::Hash) or raise ::ArgumentError, 'value must be a Hash'
|
|
22
22
|
|
|
23
|
-
@
|
|
23
|
+
@memo = {}
|
|
24
24
|
|
|
25
25
|
super
|
|
26
26
|
end
|
|
@@ -32,14 +32,38 @@ class BCDD::Context < BCDD::Result
|
|
|
32
32
|
def and_then!(source, **injected_value)
|
|
33
33
|
_call = injected_value.delete(:_call)
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
memo.merge!(injected_value)
|
|
36
36
|
|
|
37
37
|
super(source, injected_value, _call: _call)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
def [](key)
|
|
41
|
+
value[key]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def dig(...)
|
|
45
|
+
value.dig(...)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def fetch(...)
|
|
49
|
+
value.fetch(...)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def slice(...)
|
|
53
|
+
value.slice(...)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def values_at(...)
|
|
57
|
+
value.values_at(...)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def fetch_values(...)
|
|
61
|
+
value.fetch_values(...)
|
|
62
|
+
end
|
|
63
|
+
|
|
40
64
|
protected
|
|
41
65
|
|
|
42
|
-
attr_reader :
|
|
66
|
+
attr_reader :memo
|
|
43
67
|
|
|
44
68
|
private
|
|
45
69
|
|
|
@@ -54,31 +78,31 @@ class BCDD::Context < BCDD::Result
|
|
|
54
78
|
end
|
|
55
79
|
|
|
56
80
|
def call_and_then_source_method!(method, injected_value)
|
|
57
|
-
|
|
81
|
+
memo.merge!(value.merge(injected_value))
|
|
58
82
|
|
|
59
83
|
case SourceMethodArity[method]
|
|
60
84
|
when 0 then source.send(method.name)
|
|
61
|
-
when 1 then source.send(method.name, **
|
|
85
|
+
when 1 then source.send(method.name, **memo)
|
|
62
86
|
else raise Error::InvalidSourceMethodArity.build(source: source, method: method, max_arity: 1)
|
|
63
87
|
end
|
|
64
88
|
end
|
|
65
89
|
|
|
66
90
|
def call_and_then_block!(block)
|
|
67
|
-
|
|
91
|
+
memo.merge!(value)
|
|
68
92
|
|
|
69
|
-
block.call(
|
|
93
|
+
block.call(memo)
|
|
70
94
|
end
|
|
71
95
|
|
|
72
96
|
def call_and_then_callable!(source, value:, injected_value:, method_name:)
|
|
73
|
-
|
|
97
|
+
memo.merge!(value.merge(injected_value))
|
|
74
98
|
|
|
75
|
-
CallableAndThen::Caller.call(source, value:
|
|
99
|
+
CallableAndThen::Caller.call(source, value: memo, injected_value: injected_value, method_name: method_name)
|
|
76
100
|
end
|
|
77
101
|
|
|
78
102
|
def ensure_result_object(result, origin:)
|
|
79
103
|
raise_unexpected_outcome_error(result, origin) unless result.is_a?(BCDD::Context)
|
|
80
104
|
|
|
81
|
-
return result.tap { _1.
|
|
105
|
+
return result.tap { _1.memo.merge!(memo) } if result.source.equal?(source)
|
|
82
106
|
|
|
83
107
|
raise Error::InvalidResultSource.build(given_result: result, expected_source: source)
|
|
84
108
|
end
|
data/lib/bcdd/result/version.rb
CHANGED
data/sig/bcdd/context.rbs
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bcdd-result
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rodrigo Serradura
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-03-
|
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Unleash a pragmatic and observable use of Result Pattern and Railway-Oriented
|
|
14
14
|
Programming in Ruby.
|
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
160
160
|
- !ruby/object:Gem::Version
|
|
161
161
|
version: '0'
|
|
162
162
|
requirements: []
|
|
163
|
-
rubygems_version: 3.
|
|
163
|
+
rubygems_version: 3.1.6
|
|
164
164
|
signing_key:
|
|
165
165
|
specification_version: 4
|
|
166
166
|
summary: Unleash a pragmatic and observable use of Result Pattern and Railway-Oriented
|