bcdd-result 0.12.0 → 1.0.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 (104) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -2
  3. data/CHANGELOG.md +99 -16
  4. data/README.md +618 -247
  5. data/Rakefile +1 -1
  6. data/Steepfile +4 -4
  7. data/examples/multiple_listeners/Rakefile +55 -0
  8. data/examples/multiple_listeners/app/models/account/member.rb +10 -0
  9. data/examples/multiple_listeners/app/models/account/owner_creation.rb +62 -0
  10. data/examples/multiple_listeners/app/models/account.rb +11 -0
  11. data/examples/multiple_listeners/app/models/user/creation.rb +67 -0
  12. data/examples/multiple_listeners/app/models/user/token/creation.rb +51 -0
  13. data/examples/multiple_listeners/app/models/user/token.rb +7 -0
  14. data/examples/multiple_listeners/app/models/user.rb +15 -0
  15. data/examples/multiple_listeners/config/boot.rb +16 -0
  16. data/examples/multiple_listeners/config/initializers/bcdd.rb +9 -0
  17. data/examples/multiple_listeners/config.rb +27 -0
  18. data/examples/multiple_listeners/db/setup.rb +60 -0
  19. data/examples/multiple_listeners/lib/bcdd/result/event_logs_record.rb +27 -0
  20. data/examples/multiple_listeners/lib/bcdd/result/rollback_on_failure.rb +15 -0
  21. data/examples/multiple_listeners/lib/event_logs_listener/stdout.rb +60 -0
  22. data/examples/multiple_listeners/lib/runtime_breaker.rb +11 -0
  23. data/examples/service_objects/Rakefile +36 -0
  24. data/examples/service_objects/app/models/account/member.rb +10 -0
  25. data/examples/service_objects/app/models/account.rb +11 -0
  26. data/examples/service_objects/app/models/user/token.rb +7 -0
  27. data/examples/service_objects/app/models/user.rb +15 -0
  28. data/examples/service_objects/app/services/account/owner_creation.rb +47 -0
  29. data/examples/service_objects/app/services/application_service.rb +79 -0
  30. data/examples/service_objects/app/services/user/creation.rb +56 -0
  31. data/examples/service_objects/app/services/user/token/creation.rb +37 -0
  32. data/examples/service_objects/config/boot.rb +17 -0
  33. data/examples/service_objects/config/initializers/bcdd.rb +9 -0
  34. data/examples/service_objects/config.rb +20 -0
  35. data/examples/service_objects/db/setup.rb +49 -0
  36. data/examples/single_listener/Rakefile +92 -0
  37. data/examples/single_listener/app/models/account/member.rb +10 -0
  38. data/examples/single_listener/app/models/account/owner_creation.rb +62 -0
  39. data/examples/single_listener/app/models/account.rb +11 -0
  40. data/examples/single_listener/app/models/user/creation.rb +67 -0
  41. data/examples/single_listener/app/models/user/token/creation.rb +51 -0
  42. data/examples/single_listener/app/models/user/token.rb +7 -0
  43. data/examples/single_listener/app/models/user.rb +15 -0
  44. data/examples/single_listener/config/boot.rb +16 -0
  45. data/examples/single_listener/config/initializers/bcdd.rb +9 -0
  46. data/examples/single_listener/config.rb +23 -0
  47. data/examples/single_listener/db/setup.rb +49 -0
  48. data/examples/single_listener/lib/bcdd/result/rollback_on_failure.rb +15 -0
  49. data/examples/single_listener/lib/runtime_breaker.rb +11 -0
  50. data/examples/single_listener/lib/single_event_logs_listener.rb +117 -0
  51. data/lib/bcdd/{result/context → context}/callable_and_then.rb +5 -4
  52. data/lib/bcdd/{result/context → context}/expectations/mixin.rb +3 -3
  53. data/lib/bcdd/{result/context → context}/expectations.rb +2 -2
  54. data/lib/bcdd/context/failure.rb +9 -0
  55. data/lib/bcdd/{result/context → context}/mixin.rb +4 -4
  56. data/lib/bcdd/context/success.rb +37 -0
  57. data/lib/bcdd/context.rb +91 -0
  58. data/lib/bcdd/failure.rb +23 -0
  59. data/lib/bcdd/result/_self.rb +198 -0
  60. data/lib/bcdd/result/callable_and_then/caller.rb +1 -1
  61. data/lib/bcdd/result/config/switchers/addons.rb +2 -2
  62. data/lib/bcdd/result/config/switchers/constant_aliases.rb +1 -3
  63. data/lib/bcdd/result/config/switchers/features.rb +5 -5
  64. data/lib/bcdd/result/config/switchers/pattern_matching.rb +1 -1
  65. data/lib/bcdd/result/config.rb +9 -2
  66. data/lib/bcdd/result/contract/for_types.rb +1 -1
  67. data/lib/bcdd/result/contract/for_types_and_values.rb +2 -0
  68. data/lib/bcdd/result/contract/type_checker.rb +4 -0
  69. data/lib/bcdd/result/event_logs/config.rb +28 -0
  70. data/lib/bcdd/result/event_logs/listener.rb +51 -0
  71. data/lib/bcdd/result/event_logs/listeners.rb +87 -0
  72. data/lib/bcdd/result/event_logs/tracking/disabled.rb +15 -0
  73. data/lib/bcdd/result/event_logs/tracking/enabled.rb +161 -0
  74. data/lib/bcdd/result/event_logs/tracking.rb +26 -0
  75. data/lib/bcdd/result/{transitions → event_logs}/tree.rb +46 -4
  76. data/lib/bcdd/result/event_logs.rb +27 -0
  77. data/lib/bcdd/result/expectations/mixin.rb +2 -2
  78. data/lib/bcdd/result/failure.rb +1 -3
  79. data/lib/bcdd/result/ignored_types.rb +14 -0
  80. data/lib/bcdd/result/mixin.rb +2 -2
  81. data/lib/bcdd/result/success.rb +1 -3
  82. data/lib/bcdd/result/version.rb +1 -1
  83. data/lib/bcdd/result.rb +25 -191
  84. data/lib/bcdd/success.rb +23 -0
  85. data/sig/bcdd/context.rbs +175 -0
  86. data/sig/bcdd/failure.rbs +13 -0
  87. data/sig/bcdd/result/config.rbs +1 -2
  88. data/sig/bcdd/result/context.rbs +2 -165
  89. data/sig/bcdd/result/contract.rbs +1 -0
  90. data/sig/bcdd/result/event_logs.rbs +189 -0
  91. data/sig/bcdd/result/ignored_types.rbs +9 -0
  92. data/sig/bcdd/result.rbs +14 -32
  93. data/sig/bcdd/success.rbs +13 -0
  94. metadata +75 -22
  95. data/lib/bcdd/result/context/failure.rb +0 -9
  96. data/lib/bcdd/result/context/success.rb +0 -19
  97. data/lib/bcdd/result/context.rb +0 -93
  98. data/lib/bcdd/result/failure/methods.rb +0 -21
  99. data/lib/bcdd/result/success/methods.rb +0 -21
  100. data/lib/bcdd/result/transitions/tracking/disabled.rb +0 -27
  101. data/lib/bcdd/result/transitions/tracking/enabled.rb +0 -100
  102. data/lib/bcdd/result/transitions/tracking.rb +0 -20
  103. data/lib/bcdd/result/transitions.rb +0 -28
  104. data/sig/bcdd/result/transitions.rbs +0 -100
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 677f88c68eb0f745246a910bbf4a659103a5695f3c5bd74f6ac6f0ba9ff3729f
4
- data.tar.gz: 2966e659671b84bed72b2fb7ab4daaa19a1572a5480af3c19ab2a41b720d1265
3
+ metadata.gz: 78e33ee42ffa86c0eea3c6dc522ae0bec103bb70d24a1f31103b60cda7bead6e
4
+ data.tar.gz: 8919d24f1b3d903ff164717e5930f8a4e17c66ede1a93f303ffacceacdc31bb1
5
5
  SHA512:
6
- metadata.gz: ee78777c66384e185ff7c1c816ea9fa2787ab14cde530a2fb2a9ec943755b86846a0a03cbc2742c2530cf9487380e9d23ce47663de366483d77af4bfe1fa3c8c
7
- data.tar.gz: 7396cf7283c4d22dd7b03be855cf6f3a8e9c15ebbf8ef5194c34de762b99e9d6a41345066f7990be5a0e47e50da4bf38811191eb06916803881a12fab7a854b1
6
+ metadata.gz: 9c504322d2243a50ee18f1369a110af0c5fa45b07c55628f7dac30bacc2348299e1d2207474dcd15fc0a92ec071016763c4b02a0a9bbc2b402a20cf8a7b77b66
7
+ data.tar.gz: fd5706097d3057addfe8b9eccb3094ef3a3567e90f93bc3218b54ec192879a39d6a68464cac75b8606b1df25f55736a3b69c02682937816c710df5c17d8abcea
data/.rubocop.yml CHANGED
@@ -8,10 +8,17 @@ require:
8
8
  AllCops:
9
9
  NewCops: enable
10
10
  TargetRubyVersion: 2.7
11
+ Exclude:
12
+ - 'examples/**/*'
13
+ - 'vendor/**/*'
14
+ - 'spec/fixtures/**/*'
15
+ - 'tmp/**/*'
16
+ - '.git/**/*'
17
+ - 'bin/*'
11
18
 
12
19
  Lint/RescueException:
13
20
  Exclude:
14
- - lib/bcdd/result/transitions.rb
21
+ - lib/bcdd/result/event_logs/tracking/enabled.rb
15
22
 
16
23
  Layout/LineLength:
17
24
  Max: 120
@@ -25,6 +32,10 @@ Layout/MultilineMethodCallIndentation:
25
32
  Lint/UnderscorePrefixedVariableName:
26
33
  Enabled: false
27
34
 
35
+ Lint/UnusedMethodArgument:
36
+ Exclude:
37
+ - lib/bcdd/result/event_logs/listener.rb
38
+
28
39
  Style/AccessModifierDeclarations:
29
40
  Enabled: false
30
41
 
@@ -62,9 +73,13 @@ Metrics/BlockLength:
62
73
 
63
74
  Metrics/ClassLength:
64
75
  Exclude:
65
- - lib/bcdd/result.rb
76
+ - lib/bcdd/result/_self.rb
66
77
  - test/**/*.rb
67
78
 
79
+ Metrics/AbcSize:
80
+ Exclude:
81
+ - lib/bcdd/result/event_logs/tracking/enabled.rb
82
+
68
83
  Minitest/MultipleAssertions:
69
84
  Enabled: false
70
85
 
data/CHANGELOG.md CHANGED
@@ -1,44 +1,127 @@
1
1
  - [\[Unreleased\]](#unreleased)
2
- - [\[0.12.0\] - 2024-01-07](#0120---2024-01-07)
2
+ - [1.0.0 - 2024-03-16](#100---2024-03-16)
3
3
  - [Added](#added)
4
4
  - [Changed](#changed)
5
- - [\[0.11.0\] - 2024-01-02](#0110---2024-01-02)
5
+ - [\[0.13.0\] - 2024-02-01](#0130---2024-02-01)
6
6
  - [Added](#added-1)
7
7
  - [Changed](#changed-1)
8
- - [\[0.10.0\] - 2023-12-31](#0100---2023-12-31)
8
+ - [\[0.12.0\] - 2024-01-07](#0120---2024-01-07)
9
9
  - [Added](#added-2)
10
- - [\[0.9.1\] - 2023-12-12](#091---2023-12-12)
11
10
  - [Changed](#changed-2)
12
- - [Fixed](#fixed)
13
- - [\[0.9.0\] - 2023-12-12](#090---2023-12-12)
11
+ - [\[0.11.0\] - 2024-01-02](#0110---2024-01-02)
14
12
  - [Added](#added-3)
15
13
  - [Changed](#changed-3)
16
- - [\[0.8.0\] - 2023-12-11](#080---2023-12-11)
14
+ - [\[0.10.0\] - 2023-12-31](#0100---2023-12-31)
17
15
  - [Added](#added-4)
16
+ - [\[0.9.1\] - 2023-12-12](#091---2023-12-12)
18
17
  - [Changed](#changed-4)
19
- - [Removed](#removed)
20
- - [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
18
+ - [Fixed](#fixed)
19
+ - [\[0.9.0\] - 2023-12-12](#090---2023-12-12)
21
20
  - [Added](#added-5)
22
21
  - [Changed](#changed-5)
23
- - [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
22
+ - [\[0.8.0\] - 2023-12-11](#080---2023-12-11)
24
23
  - [Added](#added-6)
25
24
  - [Changed](#changed-6)
26
- - [\[0.5.0\] - 2023-10-09](#050---2023-10-09)
25
+ - [Removed](#removed)
26
+ - [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
27
27
  - [Added](#added-7)
28
- - [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
29
- - [Added](#added-8)
30
28
  - [Changed](#changed-7)
29
+ - [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
30
+ - [Added](#added-8)
31
+ - [Changed](#changed-8)
32
+ - [\[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
+ - [Added](#added-10)
36
+ - [Changed](#changed-9)
31
37
  - [Removed](#removed-1)
32
38
  - [\[0.3.0\] - 2023-09-26](#030---2023-09-26)
33
- - [Added](#added-9)
39
+ - [Added](#added-11)
34
40
  - [\[0.2.0\] - 2023-09-26](#020---2023-09-26)
35
- - [Added](#added-10)
41
+ - [Added](#added-12)
36
42
  - [Removed](#removed-2)
37
43
  - [\[0.1.0\] - 2023-09-25](#010---2023-09-25)
38
- - [Added](#added-11)
44
+ - [Added](#added-13)
39
45
 
40
46
  ## [Unreleased]
41
47
 
48
+ ## 1.0.0 - 2024-03-16
49
+
50
+ ### Added
51
+
52
+ - Add the `BCDD::Success` and `BCDD::Failure` modules. They are key to checking whether a result is a success or a failure independently of whether it is a `BCDD::Result` or a `BCDD::Context`.
53
+ - Add `BCDD::Result#type?` to check if the given type is the result type.
54
+ - Add `BCDD::Result#is?` as an alias for `BCDD::Result#type?`.
55
+ - Add `BCDD::Result#method_missing` to allow the type checking through method calls. For example, `result.ok?` will check if the result type is `:ok`.
56
+
57
+ > Note: All the methods above are available for the `BCDD::Context` as well.
58
+
59
+ ### Changed
60
+
61
+ - **(BREAKING)** Replace transitions with event_logs concept.
62
+ - The `BCDD::Result::Transitions` module was renamed to `BCDD::Result::EventLogs`
63
+ - The `BCDD::Result.transitions` to `BCDD::Result.event_logs`.
64
+
65
+ - **(BREAKING)** Change `BCDD::Result#deconstruct_keys` to return a hash with the keys `:type` and `:value` when one of these keys is present. Otherwise, it will return the value itself.
66
+
67
+ - **(BREAKING)** Replace trasitions metadata `:ids_tree`, and `:ids_matrix` with `:ids` property. This property is a hash with the following keys:
68
+ - `:tree`, a graph/tree representation of the transitions ids.
69
+ - `:level_parent`, a hash with the level (depth) of each transition and its parent id.
70
+ - `:matrix`, a matrix representation of the transitions ids. It is a simplification of the `:tree` property.
71
+
72
+ - Transform `BCDD::Result::Context` into `BCDD::Context`. But a constant alias was added to keep the old name. You can use `BCDD::Result::Context` or `BCDD::Context` to access the same class.
73
+
74
+ ## [0.13.0] - 2024-02-01
75
+
76
+ ### Added
77
+
78
+ - `BCDD::Result::Context#and_expose` - Raise error when trying to expose an invalid key.
79
+
80
+ - `BCDD::Result.configuration` - Accept freeze option (default: `true`). When true, the configuration will be frozen after the block execution.
81
+
82
+ - `BCDD::Result.config.transitions` - Add transitions feature configuration.
83
+ - `config.transitions.listener =` - Set a listener to be called during the result transitions tracking. It must be a class that includes `BCDD::Result::Transitions::Listener`.
84
+ - `config.transitions.trace_id =` - Set a lambda (must have arity 0) to be called to get a trace id. Use to correlate different or the same operation (executed multiple times).
85
+
86
+ - Add transitions metadata property `:ids_matrix`. It is a simplification of the `:ids_tree` property. The matrix rows are the direct transitions from the root transition block, and the columns are the transitions nested from the direct transitions.
87
+ ```ruby
88
+ # ids_matrix # {
89
+ 0 | 1 | 2 | 3 | 4 # 0 => [0, 0],
90
+ - | - | - | - | - # 1 => [1, 1],
91
+ 0 | | | | # 2 => [1, 2],
92
+ 1 | 1 | 2 | | # 3 => [2, 1],
93
+ 2 | 3 | | | # 4 => [3, 1],
94
+ 3 | 4 | 5 | 6 | 7 # 5 => [3, 2],
95
+ 4 | 8 | | | # 6 => [3, 3],
96
+ # 7 => [3, 4],
97
+ # 8 => [4, 1]
98
+ # }
99
+ ```
100
+
101
+ - Add `BCDD::Result::Transitions::Listeners[]` - It creates a listener of listeners, which will be called in the order they were added.
102
+
103
+ ### Changed
104
+
105
+ - **(BREAKING)** Rename `Given()` type from `:given` to `:_given_`.
106
+
107
+ - **(BREAKING)** Rename `Continue()` type from `:continued` to `:_continue_`.
108
+
109
+ - **(BREAKING)** Move transition `:source` from `:and_then` to `:result` property.
110
+
111
+ - **(BREAKING)** Rename transitions metadata property `:tree_map` to `:ids_tree`.
112
+ ```ruby
113
+ # ids_tree #
114
+ 0 # [0, [
115
+ |- 1 # [1, [[2, []]]],
116
+ | |- 2 # [3, []],
117
+ |- 3 # [4, [
118
+ |- 4 # [5, []],
119
+ | |- 5 # [6, [[7, []]]]
120
+ | |- 6 # ]],
121
+ | |- 7 # [8, []]
122
+ |- 8 # ]]
123
+ ```
124
+
42
125
  ## [0.12.0] - 2024-01-07
43
126
 
44
127
  ### Added