bcdd-result 0.4.0 → 0.6.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/.rubocop.yml +28 -0
- data/.rubocop_todo.yml +3 -13
- data/CHANGELOG.md +95 -2
- data/README.md +572 -18
- data/lib/bcdd/result/data.rb +12 -7
- data/lib/bcdd/result/error.rb +9 -1
- data/lib/bcdd/result/expectations/contract/disabled.rb +25 -0
- data/lib/bcdd/result/expectations/contract/evaluator.rb +45 -0
- data/lib/bcdd/result/expectations/contract/for_types.rb +29 -0
- data/lib/bcdd/result/expectations/contract/for_types_and_values.rb +37 -0
- data/lib/bcdd/result/expectations/contract/interface.rb +21 -0
- data/lib/bcdd/result/expectations/contract.rb +25 -0
- data/lib/bcdd/result/expectations/error.rb +15 -0
- data/lib/bcdd/result/expectations/mixin.rb +37 -0
- data/lib/bcdd/result/expectations/type_checker.rb +33 -0
- data/lib/bcdd/result/expectations.rb +50 -0
- data/lib/bcdd/result/failure.rb +1 -1
- data/lib/bcdd/result/handler/allowed_types.rb +45 -0
- data/lib/bcdd/result/handler.rb +13 -8
- data/lib/bcdd/result/mixin.rb +31 -4
- data/lib/bcdd/result/success.rb +1 -1
- data/lib/bcdd/result/version.rb +1 -1
- data/lib/bcdd/result.rb +24 -19
- data/sig/bcdd/result.rbs +229 -40
- metadata +13 -3
- data/lib/bcdd/result/type.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43af37c2ffd8d2764fc62039ac1d3e4398b2872fa25bc80192a9aca1b08dfb5
|
4
|
+
data.tar.gz: 8aaab364445f279d207390479bce6680c4ed4b7fe4b2fc026e203ddece47a398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dbac4fdded1e36d6f2af6e5c7e0d0bebfe44b489410a35445935c8da656fe244fca7a6e769a5b73d6070929e790be420887b2576cb9b523a798fe3ff759e564
|
7
|
+
data.tar.gz: 12055de39a9a3a93f69670da7b3a93a0e3749568590be14d02ce750cb5b5e5b00c7b56da422941bdea8842b073573e589d2a11681496f18f7160ddeaf3ceb7bb
|
data/.rubocop.yml
CHANGED
@@ -18,9 +18,37 @@ Layout/ExtraSpacing:
|
|
18
18
|
Style/ClassAndModuleChildren:
|
19
19
|
Enabled: false
|
20
20
|
|
21
|
+
Style/CaseEquality:
|
22
|
+
Exclude:
|
23
|
+
- lib/bcdd/result/expectations/contract/for_types_and_values.rb
|
24
|
+
|
25
|
+
Style/Lambda:
|
26
|
+
EnforcedStyle: literal
|
27
|
+
|
28
|
+
Style/MapToSet:
|
29
|
+
Exclude:
|
30
|
+
- lib/bcdd/result/expectations/contract/for_types.rb
|
31
|
+
|
32
|
+
Style/MixinGrouping:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/AccessModifierDeclarations:
|
36
|
+
Enabled: false
|
37
|
+
|
21
38
|
Naming/MethodName:
|
22
39
|
Exclude:
|
23
40
|
- lib/bcdd/result/mixin.rb
|
41
|
+
- lib/bcdd/result/expectations.rb
|
42
|
+
- lib/bcdd/result/expectations/mixin.rb
|
43
|
+
|
44
|
+
Metrics/BlockLength:
|
45
|
+
Exclude:
|
46
|
+
- bcdd-result.gemspec
|
47
|
+
- test/**/*.rb
|
48
|
+
|
49
|
+
Metrics/ClassLength:
|
50
|
+
Exclude:
|
51
|
+
- test/**/*.rb
|
24
52
|
|
25
53
|
Minitest/MultipleAssertions:
|
26
54
|
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
@@ -1,22 +1,12 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2023-
|
3
|
+
# on 2023-10-02 02:37:50 UTC using RuboCop version 1.56.3.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 24
|
10
10
|
# Configuration parameters: AllowedConstants.
|
11
11
|
Style/Documentation:
|
12
|
-
|
13
|
-
- 'spec/**/*'
|
14
|
-
- 'test/**/*'
|
15
|
-
- 'lib/bcdd/result.rb'
|
16
|
-
- 'lib/bcdd/result/data.rb'
|
17
|
-
- 'lib/bcdd/result/error.rb'
|
18
|
-
- 'lib/bcdd/result/failure.rb'
|
19
|
-
- 'lib/bcdd/result/handler.rb'
|
20
|
-
- 'lib/bcdd/result/mixin.rb'
|
21
|
-
- 'lib/bcdd/result/success.rb'
|
22
|
-
- 'lib/bcdd/result/type.rb'
|
12
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,99 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0] - 2023-10-11
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Add `BCDD::Result.mixin` to be included or extended in any object. It will add `Success()` and `Failure()` to the target object (the object who receives the include/extend).
|
8
|
+
|
9
|
+
- Add `BCDD::Result.mixin(with: :Continue)`. This addon will add a `Continue(value)` method to the target object to produce a `Success(:continued, value)` result.
|
10
|
+
|
11
|
+
- Add `BCDD::Result::Expectations.mixin(with: :Continue)`, it is similar to `BCDD::Result.mixin(with: :Continue)`, the key difference is that the `Continue(value)` will be ignored by the expectations. This is extremely useful when you want to use `Continue(value)` to chain operations, but you don't want to declare N success types in the expectations.
|
12
|
+
|
13
|
+
- Increase the arity of `BCDD::Result#and_then`. Now, it can receive a second argument (a value to be injected and shared with the subject's method).
|
14
|
+
|
15
|
+
- Increase the arity (maximum of 2) for the methods called through `BCDD::Result#and_then`. The second argument is the value injected by `BCDD::Result#and_then`.
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
|
19
|
+
- **(BREAKING)** Make `BCDD::Result::Mixin` be a private constant. The `BCDD::Result.mixin` method is the new way to use it.
|
20
|
+
|
21
|
+
## [0.5.0] - 2023-10-09
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Add `BCDD::Result::Expectations` to define contracts for your results. There are two ways to use it: the standalone (`BCDD::Result::Expectations.new`) and the mixin (`BCDD::Result::Expectations.mixin`) mode.
|
26
|
+
|
27
|
+
The main difference is that the mixin mode will use the target object (who receives the include/extend) as the result's subject (like the `BCDD::Result::Mixin` does), while the standalone mode won't.
|
28
|
+
|
29
|
+
**Standalone mode:**
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
module Divide
|
33
|
+
Expected = BCDD::Result::Expectations.new(
|
34
|
+
success: {
|
35
|
+
numbers: ->(value) { value.is_a?(Array) && value.size == 2 && value.all?(Numeric) },
|
36
|
+
division_completed: Numeric
|
37
|
+
},
|
38
|
+
failure: {
|
39
|
+
invalid_arg: String,
|
40
|
+
division_by_zero: String
|
41
|
+
}
|
42
|
+
)
|
43
|
+
|
44
|
+
def self.call(arg1, arg2)
|
45
|
+
arg1.is_a?(Numeric) or return Expected::Failure(:invalid_arg, 'arg1 must be numeric')
|
46
|
+
arg2.is_a?(Numeric) or return Expected::Failure(:invalid_arg, 'arg2 must be numeric')
|
47
|
+
|
48
|
+
arg2.zero? and return Expected::Failure(:division_by_zero, 'arg2 must not be zero')
|
49
|
+
|
50
|
+
Expected::Success(:division_completed, arg1 / arg2)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
**Mixin mode:**
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class Divide
|
59
|
+
include BCDD::Result::Expectations.mixin(
|
60
|
+
success: {
|
61
|
+
numbers: ->(value) { value.is_a?(Array) && value.size == 2 && value.all?(Numeric) },
|
62
|
+
division_completed: Numeric
|
63
|
+
},
|
64
|
+
failure: {
|
65
|
+
invalid_arg: String,
|
66
|
+
division_by_zero: String
|
67
|
+
}
|
68
|
+
)
|
69
|
+
|
70
|
+
def call(arg1, arg2)
|
71
|
+
validate_numbers(arg1, arg2)
|
72
|
+
.and_then(:validate_non_zero)
|
73
|
+
.and_then(:divide)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def validate_numbers(arg1, arg2)
|
79
|
+
arg1.is_a?(Numeric) or return Failure(:invalid_arg, 'arg1 must be numeric')
|
80
|
+
arg2.is_a?(Numeric) or return Failure(:invalid_arg, 'arg2 must be numeric')
|
81
|
+
|
82
|
+
Success(:numbers, [arg1, arg2])
|
83
|
+
end
|
84
|
+
|
85
|
+
def validate_non_zero(numbers)
|
86
|
+
return Success(:numbers, numbers) unless numbers.last.zero?
|
87
|
+
|
88
|
+
Failure(:division_by_zero, 'arg2 must not be zero')
|
89
|
+
end
|
90
|
+
|
91
|
+
def divide((number1, number2))
|
92
|
+
Success(:division_completed, number1 / number2)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
3
97
|
## [0.4.0] - 2023-09-28
|
4
98
|
|
5
99
|
### Added
|
@@ -78,8 +172,7 @@ end
|
|
78
172
|
|
79
173
|
```ruby
|
80
174
|
module Divide
|
81
|
-
extend BCDD::Resultable
|
82
|
-
extend self
|
175
|
+
extend self, BCDD::Resultable
|
83
176
|
|
84
177
|
def call(arg1, arg2)
|
85
178
|
validate_numbers(arg1, arg2)
|