bcdd-result 0.6.0 → 0.8.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +31 -11
  3. data/CHANGELOG.md +148 -0
  4. data/README.md +849 -242
  5. data/Rakefile +9 -3
  6. data/Steepfile +1 -1
  7. data/lib/bcdd/result/config/constant_alias.rb +33 -0
  8. data/lib/bcdd/result/config/options.rb +26 -0
  9. data/lib/bcdd/result/config/switcher.rb +82 -0
  10. data/lib/bcdd/result/config.rb +71 -0
  11. data/lib/bcdd/result/context/expectations/mixin.rb +23 -0
  12. data/lib/bcdd/result/context/expectations.rb +25 -0
  13. data/lib/bcdd/result/context/failure.rb +9 -0
  14. data/lib/bcdd/result/context/mixin.rb +41 -0
  15. data/lib/bcdd/result/context/success.rb +15 -0
  16. data/lib/bcdd/result/context.rb +74 -0
  17. data/lib/bcdd/result/{expectations/contract → contract}/disabled.rb +2 -2
  18. data/lib/bcdd/result/{expectations → contract}/error.rb +5 -3
  19. data/lib/bcdd/result/{expectations/contract → contract}/evaluator.rb +2 -2
  20. data/lib/bcdd/result/{expectations/contract → contract}/for_types.rb +2 -2
  21. data/lib/bcdd/result/contract/for_types_and_values.rb +44 -0
  22. data/lib/bcdd/result/contract/interface.rb +21 -0
  23. data/lib/bcdd/result/{expectations → contract}/type_checker.rb +1 -1
  24. data/lib/bcdd/result/contract.rb +33 -0
  25. data/lib/bcdd/result/error.rb +7 -9
  26. data/lib/bcdd/result/expectations/mixin.rb +19 -12
  27. data/lib/bcdd/result/expectations.rb +51 -36
  28. data/lib/bcdd/result/failure/methods.rb +21 -0
  29. data/lib/bcdd/result/failure.rb +2 -16
  30. data/lib/bcdd/result/mixin.rb +26 -8
  31. data/lib/bcdd/result/success/methods.rb +21 -0
  32. data/lib/bcdd/result/success.rb +2 -16
  33. data/lib/bcdd/result/version.rb +1 -1
  34. data/lib/bcdd/result.rb +17 -4
  35. data/lib/bcdd-result.rb +3 -0
  36. data/sig/bcdd/result.rbs +340 -88
  37. metadata +27 -16
  38. data/lib/bcdd/result/expectations/contract/for_types_and_values.rb +0 -37
  39. data/lib/bcdd/result/expectations/contract/interface.rb +0 -21
  40. data/lib/bcdd/result/expectations/contract.rb +0 -25
  41. data/lib/result.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d43af37c2ffd8d2764fc62039ac1d3e4398b2872fa25bc80192a9aca1b08dfb5
4
- data.tar.gz: 8aaab364445f279d207390479bce6680c4ed4b7fe4b2fc026e203ddece47a398
3
+ metadata.gz: 2b49559a4258169692f89f3263c14485cde2e17e36c90ccde9bf88dab355d458
4
+ data.tar.gz: b62c215886f572f942a752767db89544ae5e483a496975882fcc9108d99edc0f
5
5
  SHA512:
6
- metadata.gz: 6dbac4fdded1e36d6f2af6e5c7e0d0bebfe44b489410a35445935c8da656fe244fca7a6e769a5b73d6070929e790be420887b2576cb9b523a798fe3ff759e564
7
- data.tar.gz: 12055de39a9a3a93f69670da7b3a93a0e3749568590be14d02ce750cb5b5e5b00c7b56da422941bdea8842b073573e589d2a11681496f18f7160ddeaf3ceb7bb
6
+ metadata.gz: 2794daec03ab43d9d9549887dae87d0138195f0c85f65ddcc1015d74a9a940c639e7dc73086c9f948de00c8ce95d576105a3ad9e671b068d56d39e4ef075c3ff
7
+ data.tar.gz: 197572b1a2dc61a72de744af1bbb50a642731dc4e248133164da36fb8ff8d257fe89c2874798ea9f77533aa462e386dd002cc2dd25f241ca12cd02ff8d080fa4
data/.rubocop.yml CHANGED
@@ -15,31 +15,41 @@ Layout/LineLength:
15
15
  Layout/ExtraSpacing:
16
16
  AllowBeforeTrailingComments: true
17
17
 
18
- Style/ClassAndModuleChildren:
18
+ Layout/MultilineMethodCallIndentation:
19
+ Enabled: false
20
+
21
+ Lint/UnderscorePrefixedVariableName:
22
+ Enabled: false
23
+
24
+ Style/AccessModifierDeclarations:
19
25
  Enabled: false
20
26
 
21
27
  Style/CaseEquality:
22
- Exclude:
23
- - lib/bcdd/result/expectations/contract/for_types_and_values.rb
28
+ Enabled: false
29
+
30
+ Style/ClassAndModuleChildren:
31
+ Enabled: false
24
32
 
25
33
  Style/Lambda:
26
34
  EnforcedStyle: literal
27
35
 
36
+ Style/ParallelAssignment:
37
+ Enabled: false
38
+
39
+ Style/SingleLineMethods:
40
+ Enabled: false
41
+
28
42
  Style/MapToSet:
29
- Exclude:
30
- - lib/bcdd/result/expectations/contract/for_types.rb
43
+ Enabled: false
31
44
 
32
45
  Style/MixinGrouping:
33
46
  Enabled: false
34
47
 
35
- Style/AccessModifierDeclarations:
48
+ Naming/MethodName:
36
49
  Enabled: false
37
50
 
38
- Naming/MethodName:
39
- Exclude:
40
- - lib/bcdd/result/mixin.rb
41
- - lib/bcdd/result/expectations.rb
42
- - lib/bcdd/result/expectations/mixin.rb
51
+ Naming/VariableName:
52
+ Enabled: false
43
53
 
44
54
  Metrics/BlockLength:
45
55
  Exclude:
@@ -52,3 +62,13 @@ Metrics/ClassLength:
52
62
 
53
63
  Minitest/MultipleAssertions:
54
64
  Enabled: false
65
+
66
+ Minitest/AssertEmptyLiteral:
67
+ Enabled: false
68
+
69
+ Minitest/AssertOperator:
70
+ Enabled: false
71
+
72
+ Naming/FileName:
73
+ Exclude:
74
+ - lib/bcdd-result.rb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,153 @@
1
+ - [\[Unreleased\]](#unreleased)
2
+ - [\[0.8.0\] - 2023-12-11](#080---2023-12-11)
3
+ - [Added](#added)
4
+ - [Changed](#changed)
5
+ - [Removed](#removed)
6
+ - [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
7
+ - [Added](#added-1)
8
+ - [Changed](#changed-1)
9
+ - [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
10
+ - [Added](#added-2)
11
+ - [Changed](#changed-2)
12
+ - [\[0.5.0\] - 2023-10-09](#050---2023-10-09)
13
+ - [Added](#added-3)
14
+ - [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
15
+ - [Added](#added-4)
16
+ - [Changed](#changed-3)
17
+ - [Removed](#removed-1)
18
+ - [\[0.3.0\] - 2023-09-26](#030---2023-09-26)
19
+ - [Added](#added-5)
20
+ - [\[0.2.0\] - 2023-09-26](#020---2023-09-26)
21
+ - [Added](#added-6)
22
+ - [Removed](#removed-2)
23
+ - [\[0.1.0\] - 2023-09-25](#010---2023-09-25)
24
+ - [Added](#added-7)
25
+
1
26
  ## [Unreleased]
2
27
 
28
+ ## [0.8.0] - 2023-12-11
29
+
30
+ ### Added
31
+
32
+ - Add `BCDD::Result.config`
33
+ - **Feature**
34
+ ```ruby
35
+ BCDD::Result.config.feature.options
36
+ BCDD::Result.config.feature.enabled?(:expectations)
37
+ BCDD::Result.config.feature.enable!(:expectations)
38
+ BCDD::Result.config.feature.disable!(:expectations)
39
+ ```
40
+ - **Default Add-ons**
41
+ ```ruby
42
+ BCDD::Result.config.addon.options
43
+ BCDD::Result.config.addon.enabled?(:continue)
44
+ BCDD::Result.config.addon.enable!(:continue)
45
+ BCDD::Result.config.addon.disable!(:continue)
46
+ ```
47
+ - **Pattern matching**
48
+ ```ruby
49
+ BCDD::Result.config.pattern_matching.options
50
+ BCDD::Result.config.pattern_matching.enabled?(:nil_as_valid_value_checking)
51
+ BCDD::Result.config.pattern_matching.enable!(:nil_as_valid_value_checking)
52
+ BCDD::Result.config.pattern_matching.disable!(:nil_as_valid_value_checking)
53
+ ```
54
+ - **Constant Aliases**
55
+ ```ruby
56
+ BCDD::Result.config.constant_alias.options
57
+ BCDD::Result.config.constant_alias.enabled?('Result')
58
+ BCDD::Result.config.constant_alias.enable!('Result')
59
+ BCDD::Result.config.constant_alias.disable!('Result')
60
+ ```
61
+
62
+ - Add `BCDD::Result::configuration`. It freezes the configuration, disallowing methods that promote changes but allowing the query ones. You can use this feature to ensure integrity in your configuration.
63
+ ```ruby
64
+ BCDD::Result.configuration do |config|
65
+ config.addon.enable!(:continue)
66
+
67
+ config.constant_alias.enable!('Result')
68
+
69
+ config.pattern_matching.disable!(:nil_as_valid_value_checking)
70
+
71
+ config.feature.disable!(:expectations) if ::Rails.env.production?
72
+ end
73
+
74
+ BCDD::Result.config.addon.enabled?(:continue) # true
75
+ BCDD::Result.config.constant_alias.enabled?('Result') # true
76
+
77
+ BCDD::Result.config.addon.disable!(:continue) # raises FrozenError
78
+ BCDD::Result.config.constant_alias.disable!('Result') # raises FrozenError
79
+ ```
80
+
81
+ - Allow the pattern matching feature to be turned on/off through the `BCDD::Result::Expectations.mixin`. Now, it can be used without enabling it for the whole project.
82
+ ```ruby
83
+ extend BCDD::Result::Expectations.mixin(
84
+ config: {
85
+ addon: { continue: false },
86
+ pattern_matching: { nil_as_valid_value_checking: true },
87
+ },
88
+ success: {
89
+ numbers: ->(value) { value => [Numeric, Numeric] },
90
+ division_completed: Numeric
91
+ },
92
+ failure: {
93
+ invalid_arg: String,
94
+ division_by_zero: String
95
+ }
96
+ )
97
+ ```
98
+
99
+ ### Changed
100
+
101
+ - **(BREAKING)** Replace `BCDD::Result::Contract.nil_as_valid_value_checking!` with `BCDD::Result::Config.pattern_matching.enable!(:nil_as_valid_value_checking)`.
102
+
103
+ - **(BREAKING)** Replace `BCDD::Result::Contract.nil_as_valid_value_checking?` with `BCDD::Result::Config.pattern_matching.enabled?(:nil_as_valid_value_checking)`.
104
+
105
+ - **(BREAKING)** Replace `mixin(with:)` with `mixin(config:)` keyword argument.
106
+
107
+ - **(BREAKING)** Change the addons definition.
108
+ - **From**
109
+ ```ruby
110
+ BCDD::Result.mixin(with: :Continue)
111
+ BCDD::Result.mixin(with: [:Continue])
112
+ ```
113
+ - **To**
114
+ ```ruby
115
+ BCDD::Result.mixin(config: { addon: { continue: true } })
116
+ ```
117
+ - These examples are valid to all kinds of mixins (`BCDD::Result.mixin`, `BCDD::Result::Context.mixin`, `BCDD::Result::Expectations.mixin`, `BCDD::Result::Context::Expectations.mixin`)
118
+
119
+ ### Removed
120
+
121
+ - **(BREAKING)** Remove the `lib/result` file. Now you can define `Result` as an alias for `BCDD::Result` using `BCDD::Result::Config.constant_alias.enable!('Result')`.
122
+
123
+ ## [0.7.0] - 2023-10-27
124
+
125
+ ### Added
126
+
127
+ - 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/>
128
+ 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.
129
+
130
+ - 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`.
131
+ - The `BCDD::Result::Context.mixin` and `BCDD::Result::Context::Expectations.mixin` support the `with: :Continue` option.
132
+
133
+ - 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.
134
+
135
+ - Add `BCDD::Result::Success::Methods` to be share common methods between `BCDD::Result::Success` and `BCDD::Result::Context::Success`.
136
+
137
+ - Add `BCDD::Result::Failure::Methods` to be share common methods between `BCDD::Failure::Success` and `BCDD::Result::Context::Failure`.
138
+
139
+ - 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).
140
+
141
+ - 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.
142
+
143
+ ### Changed
144
+
145
+ - **(BREAKING)** Rename `BCDD::Result::WrongResultSubject` to `BCDD::Result::Error::InvalidResultSubject`.
146
+ - **(BREAKING)** Rename `BCDD::Result::WrongSubjectMethodArity` to `BCDD::Result::Error::InvalidSubjectMethodArity`.
147
+ - **(BREAKING)** Rename the constant produced by `BCDD::Result::Expectations.mixins` from `Expected` to `Result`.
148
+ - Extract the major part of the `BCDD::Result::Expectations` components/features to `BCDD::Result::Contract`.
149
+ - **(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`.
150
+
3
151
  ## [0.6.0] - 2023-10-11
4
152
 
5
153
  ### Added