bcdd-result 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a6bfbf4821c7674fd0af6dbd4e88d274cbf14595eff278ef40ebdaf5bf4490a
4
- data.tar.gz: 9cc905974762089c3f3827ac40aa730040ad9e88176e8cae0275954bedd6e7a8
3
+ metadata.gz: d43af37c2ffd8d2764fc62039ac1d3e4398b2872fa25bc80192a9aca1b08dfb5
4
+ data.tar.gz: 8aaab364445f279d207390479bce6680c4ed4b7fe4b2fc026e203ddece47a398
5
5
  SHA512:
6
- metadata.gz: 5446879d905a42e257b3dd5724b6dc53a455cf2ec8e3fd7a5f339f74216e8d87ce779912dd4124163a6af4a19052e558382e74e7b20a434420b8d2eae055ab37
7
- data.tar.gz: c91588b64905a6d86b84dc04db128e42fb0c570cf1e973ccd76563b0126e0e30d31764e918aa93aa71b06115a95c984299d4a57c249391d366d8738469aa8ecb
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-09-29 01:50:30 UTC using RuboCop version 1.56.3.
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: 14
9
+ # Offense count: 24
10
10
  # Configuration parameters: AllowedConstants.
11
11
  Style/Documentation:
12
- Exclude:
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)