bcdd-result 0.5.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +30 -10
  3. data/CHANGELOG.md +49 -2
  4. data/README.md +709 -127
  5. data/lib/bcdd/result/context/expectations/mixin.rb +35 -0
  6. data/lib/bcdd/result/context/expectations.rb +41 -0
  7. data/lib/bcdd/result/context/failure.rb +9 -0
  8. data/lib/bcdd/result/context/mixin.rb +38 -0
  9. data/lib/bcdd/result/context/success.rb +15 -0
  10. data/lib/bcdd/result/context.rb +74 -0
  11. data/lib/bcdd/result/{expectations/contract → contract}/disabled.rb +2 -2
  12. data/lib/bcdd/result/{expectations → contract}/error.rb +5 -3
  13. data/lib/bcdd/result/{expectations/contract → contract}/evaluator.rb +2 -2
  14. data/lib/bcdd/result/{expectations/contract → contract}/for_types.rb +2 -2
  15. data/lib/bcdd/result/{expectations/contract → contract}/for_types_and_values.rb +10 -8
  16. data/lib/bcdd/result/contract/interface.rb +21 -0
  17. data/lib/bcdd/result/{expectations → contract}/type_checker.rb +1 -1
  18. data/lib/bcdd/result/contract.rb +43 -0
  19. data/lib/bcdd/result/error.rb +7 -9
  20. data/lib/bcdd/result/expectations/mixin.rb +42 -0
  21. data/lib/bcdd/result/expectations.rb +27 -48
  22. data/lib/bcdd/result/failure/methods.rb +21 -0
  23. data/lib/bcdd/result/failure.rb +2 -16
  24. data/lib/bcdd/result/mixin.rb +36 -4
  25. data/lib/bcdd/result/success/methods.rb +21 -0
  26. data/lib/bcdd/result/success.rb +2 -16
  27. data/lib/bcdd/result/version.rb +1 -1
  28. data/lib/bcdd/result.rb +11 -6
  29. data/sig/bcdd/result.rbs +245 -71
  30. metadata +19 -10
  31. data/lib/bcdd/result/expectations/contract/interface.rb +0 -21
  32. data/lib/bcdd/result/expectations/contract.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4eb0878d2e7d75bb4cfd55c0d112db0f14b4c43255d3e02d60ec60c0f9c2d6e
4
- data.tar.gz: dd8ee0d7239a63b486de7efb7876c40db1942f2d54a383ed0c67bb86e20b0622
3
+ metadata.gz: dda53cc516fcb8d18b2bd3c8431f2ca8d5d7363b6e58fd57d3fe3d1b49877e20
4
+ data.tar.gz: 367b97ba29f35dd2d6918817db38a2253929252c616aebcb47d7fc024888d258
5
5
  SHA512:
6
- metadata.gz: '08f8ed0b78bcf298711a52b20be08908dc3000888a94b8bd3df289fa3682909bb87ba294c2ba42a482678af0f9dd5bff5a267169a256ca7cb0a23c40b961613c'
7
- data.tar.gz: cc15020416823a965c29ece5947875817df0ccc6b7c21f4dc534ba24aa68e10134a4333d0e36bcb8afc08719f9e6aeea1741ea51be6b373cc8efc61e82b08a7f
6
+ metadata.gz: 3618c5090981f4923977708944d94c257879fe57c06d1b2c922b7378c026e4d39c8ab13fdf64ad6277cfea4229d43d120b0d3ec3d7cb676676f0bf8d6714892d
7
+ data.tar.gz: 880a2f0ebcd8f7bb9ee32b2967c39011211e604981d43b59735fc912ec414635bc152ab13549ba64c87af987f66a7c334fae909cd860d3f36f6b092565b8cf24
data/.rubocop.yml CHANGED
@@ -15,26 +15,40 @@ Layout/LineLength:
15
15
  Layout/ExtraSpacing:
16
16
  AllowBeforeTrailingComments: true
17
17
 
18
- Style/ClassAndModuleChildren:
18
+ Layout/MultilineMethodCallIndentation:
19
19
  Enabled: false
20
20
 
21
- Style/MapToSet:
22
- Exclude:
23
- - lib/bcdd/result/expectations/contract/for_types.rb
21
+ Lint/UnderscorePrefixedVariableName:
22
+ Enabled: false
23
+
24
+ Style/AccessModifierDeclarations:
25
+ Enabled: false
24
26
 
25
27
  Style/CaseEquality:
26
- Exclude:
27
- - lib/bcdd/result/expectations/contract/for_types_and_values.rb
28
+ Enabled: false
29
+
30
+ Style/ClassAndModuleChildren:
31
+ Enabled: false
28
32
 
29
33
  Style/Lambda:
30
34
  EnforcedStyle: literal
31
35
 
36
+ Style/ParallelAssignment:
37
+ Enabled: false
38
+
39
+ Style/SingleLineMethods:
40
+ Enabled: false
41
+
42
+ Style/MapToSet:
43
+ Enabled: false
44
+
45
+ Style/MixinGrouping:
46
+ Enabled: false
47
+
32
48
  Naming/MethodName:
33
- Exclude:
34
- - lib/bcdd/result/mixin.rb
35
- - lib/bcdd/result/expectations.rb
49
+ Enabled: false
36
50
 
37
- Minitest/MultipleAssertions:
51
+ Naming/VariableName:
38
52
  Enabled: false
39
53
 
40
54
  Metrics/BlockLength:
@@ -45,3 +59,9 @@ Metrics/BlockLength:
45
59
  Metrics/ClassLength:
46
60
  Exclude:
47
61
  - test/**/*.rb
62
+
63
+ Minitest/MultipleAssertions:
64
+ Enabled: false
65
+
66
+ Minitest/AssertEmptyLiteral:
67
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,7 +1,55 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.7.0] - 2023-10-27
4
+
5
+ ### Added
6
+
7
+ - Add `BCDD::Result::Context`. It is a `BCDD::Result`, meaning it has all the features of the `BCDD::Result`. The main difference is that it only accepts keyword arguments as a value, which applies to the `and_then`: The called methods must receive keyword arguments, and the dependency injection will be performed through keyword arguments.<br/><br/>
8
+ As the input/output are hashes, the results of each `and_then` call will automatically accumulate. This is useful in operations chaining, as the result of the previous operations will be automatically available for the next one. Because of this behavior, the `BCDD::Result::Context` has the `#and_expose` method to expose only the desired keys from the accumulated result.
9
+
10
+ - Add `BCDD::Result::Context::Expectations.new` and `BCDD::Result::Context::Expectations.mixin`. Both are similar to `BCDD::Result::Expectations.new` and `BCDD::Result::Expectations.mixin`, but they are for `BCDD::Result::Context` instead of `BCDD::Result`.
11
+ - The `BCDD::Result::Context.mixin` and `BCDD::Result::Context::Expectations.mixin` support the `with: :Continue` option.
12
+
13
+ - Enhance Pattern Matching support. When a `NoMatchingPatternError` occurs inside a value checking, the `BCDD::Result::Contract::Error::UnexpectedValue` message will include the value and the expected patterns.
14
+
15
+ - Add `BCDD::Result::Success::Methods` to be share common methods between `BCDD::Result::Success` and `BCDD::Result::Context::Success`.
16
+
17
+ - Add `BCDD::Result::Failure::Methods` to be share common methods between `BCDD::Failure::Success` and `BCDD::Result::Context::Failure`.
18
+
19
+ - Make all mixin generators produce a named module. The module name will be added to the target class/module (who included/extended a `BCDD::Result`/`BCDD::Result::Context` mixin module).
20
+
21
+ - Add `BCDD::Result::Contract.nil_as_valid_value_checking!`. Please use this method when using the one-line pattern-matching operators on the result's value expectations.
22
+
23
+ ### Changed
24
+
25
+ - **(BREAKING)** Rename `BCDD::Result::WrongResultSubject` to `BCDD::Result::Error::InvalidResultSubject`.
26
+ - **(BREAKING)** Rename `BCDD::Result::WrongSubjectMethodArity` to `BCDD::Result::Error::InvalidSubjectMethodArity`.
27
+ - **(BREAKING)** Rename the constant produced by `BCDD::Result::Expectations.mixins` from `Expected` to `Result`.
28
+ - Extract the major part of the `BCDD::Result::Expectations` components/features to `BCDD::Result::Contract`.
29
+ - **(BREAKING)** `BCDD::Result::Expectations::Error` became `BCDD::Result::Contract::Error`. So, `BCDD::Result::Expectations::Error::UnexpectedType` and `BCDD::Result::Expectations::Error::UnexpectedValue` are now `BCDD::Result::Contract::Error::UnexpectedType` and `BCDD::Result::Contract::Error::UnexpectedValue`.
30
+
31
+ ## [0.6.0] - 2023-10-11
32
+
33
+ ### Added
34
+
35
+ - 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).
36
+
37
+ - 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.
38
+
39
+ - 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.
40
+
41
+ - 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).
42
+
43
+ - 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`.
44
+
45
+ ### Changed
46
+
47
+ - **(BREAKING)** Make `BCDD::Result::Mixin` be a private constant. The `BCDD::Result.mixin` method is the new way to use it.
48
+
3
49
  ## [0.5.0] - 2023-10-09
4
50
 
51
+ ### Added
52
+
5
53
  - 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.
6
54
 
7
55
  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.
@@ -152,8 +200,7 @@ end
152
200
 
153
201
  ```ruby
154
202
  module Divide
155
- extend BCDD::Resultable
156
- extend self
203
+ extend self, BCDD::Resultable
157
204
 
158
205
  def call(arg1, arg2)
159
206
  validate_numbers(arg1, arg2)