Skip to content

Commit 41e18fa

Browse files
committed
Change addons definition (mixin + config)
1 parent 8689802 commit 41e18fa

File tree

14 files changed

+35
-37
lines changed

14 files changed

+35
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
```
5454
- **To**
5555
```ruby
56-
BCDD::Result.mixin(with: :continue)
57-
BCDD::Result.mixin(with: [:continue])
58-
BCDD::Result.mixin(with: { continue: true })
56+
BCDD::Result.mixin(config: { addon: { continue: true } })
5957
```
6058
- 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`)
6159

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -746,10 +746,10 @@ class Divide
746746
private
747747

748748
def validate_numbers
749-
arg1.is_a?(::Numeric) or return BCDD::Result::Failure(:invalid_arg, 'arg1 must be numeric') # This will raise an error
749+
arg1.is_a?(::Numeric) or return Failure(:invalid_arg, 'arg1 must be numeric') # This will raise an error
750750
arg2.is_a?(::Numeric) or return Failure(:invalid_arg, 'arg2 must be numeric')
751751

752-
BCDD::Result::Success(:ok, [arg1, arg2]) # This will raise an error
752+
Success(:ok, [arg1, arg2]) # This will raise an error
753753
end
754754

755755
def validate_non_zero(numbers)
@@ -838,7 +838,7 @@ This addon will create the `Continue(value)` method, which will know how to prod
838838

839839
```ruby
840840
module Divide
841-
extend self, BCDD::Result.mixin(config: :continue)
841+
extend self, BCDD::Result.mixin(config: { addon: { continue: true } })
842842

843843
def call(arg1, arg2)
844844
validate_numbers(arg1, arg2)
@@ -947,10 +947,10 @@ class Divide
947947
end
948948
```
949949

950-
This mode also defines an `Expected` constant to be used inside and outside the module.
950+
This mode also defines an `Result` constant to be used inside and outside the module.
951951

952952
> **PROTIP:**
953-
> You can use the `Expected` constant to mock the result's type and value in your tests. As they will have the exact expectations, your tests will check if the result clients are handling the result correctly.
953+
> You can use the `Result` constant to mock the result's type and value in your tests. As they will have the exact expectations, your tests will check if the result clients are handling the result correctly.
954954
955955
Now that you know the two modes, let's understand how expectations can be beneficial and powerful for defining contracts.
956956

@@ -1274,12 +1274,12 @@ The `BCDD::Result::Expectations.mixin` also accepts the `with:` argument. It is
12741274

12751275
**Continue**
12761276

1277-
It is similar to `BCDD::Result.mixin(config: :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.
1277+
It is similar to `BCDD::Result.mixin(config: { addon: { continue: true } })`, 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.
12781278

12791279
```ruby
12801280
class Divide
12811281
include BCDD::Result::Expectations.mixin(
1282-
config: :continue,
1282+
config: { addon: { continue: true } },
12831283
success: :division_completed,
12841284
failure: %i[invalid_arg division_by_zero]
12851285
)
@@ -1581,7 +1581,7 @@ The `BCDD::Result::Context.mixin` and `BCDD::Result::Context::Expectations.mixin
15811581

15821582
**Continue**
15831583

1584-
The `BCDD::Result::Context.mixin(config: :continue)` or `BCDD::Result::Context::Expectations.mixin(config: :continue)` adds a `Continue(**input)` that will be ignored by the expectations. This is extremely useful when you want to use `Continue()` to chain operations, but you don't want to declare N success types in the expectations.
1584+
The `BCDD::Result::Context.mixin(config: { addon: { continue: true } })` or `BCDD::Result::Context::Expectations.mixin(config: { addon: { continue: true } })` adds a `Continue(**input)` that will be ignored by the expectations. This is extremely useful when you want to use `Continue()` to chain operations, but you don't want to declare N success types in the expectations.
15851585

15861586
Let's use a mix of `BCDD::Result::Context` features to see in action with this add-on:
15871587

@@ -1596,7 +1596,7 @@ module Divide
15961596
require 'logger'
15971597

15981598
extend self, BCDD::Result::Context::Expectations.mixin(
1599-
config: :continue,
1599+
config: { addon: { continue: true } },
16001600
success: {
16011601
division_completed: ->(value) { value => { number: Numeric } }
16021602
},

lib/bcdd/result/context/expectations/mixin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ module Continuable
1515

1616
OPTIONS = { continue: Continuable }.freeze
1717

18-
def self.options(names)
19-
::BCDD::Result::Config::Options.filter(names, OPTIONS)
18+
def self.options(config_flags)
19+
::BCDD::Result::Config::Options.unwrap(options: { addon: OPTIONS }, flags: config_flags)
2020
end
2121
end
2222
end

lib/bcdd/result/context/mixin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module Continuable
2323

2424
OPTIONS = { continue: Continuable }.freeze
2525

26-
def self.options(names)
27-
::BCDD::Result::Config::Options.filter(names, OPTIONS)
26+
def self.options(config_flags)
27+
::BCDD::Result::Config::Options.unwrap(options: { addon: OPTIONS }, flags: config_flags)
2828
end
2929
end
3030
end

lib/bcdd/result/expectations/mixin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module Continuable
3636

3737
OPTIONS = { continue: Continuable }.freeze
3838

39-
def self.options(names)
40-
Config::Options.filter(names, OPTIONS)
39+
def self.options(config_flags)
40+
Config::Options.unwrap(options: { addon: OPTIONS }, flags: config_flags)
4141
end
4242
end
4343
end

lib/bcdd/result/mixin.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ module Continuable
3030

3131
OPTIONS = { continue: Continuable }.freeze
3232

33-
def self.options(names)
34-
Config::Options.filter(names, OPTIONS)
33+
def self.options(config_flags)
34+
Config::Options.unwrap(options: { addon: OPTIONS }, flags: config_flags)
3535
end
3636
end
3737
end

sig/bcdd/result.rbs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ class BCDD::Result
118118

119119
OPTIONS: Hash[Symbol, Module]
120120

121-
def self.options: (Array[Symbol]) -> Array[Module]
121+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
122122
end
123123
end
124124

125-
def self.mixin: (?config: Array[Symbol]) -> Module
125+
def self.mixin: (?config: Hash[Symbol, Hash[Symbol, bool]]) -> Module
126126

127127
def self.mixin_module: -> singleton(BCDD::Result::Mixin)
128128
end
@@ -342,7 +342,7 @@ end
342342

343343
class BCDD::Result::Expectations
344344
def self.mixin: (
345-
?config: Symbol,
345+
?config: Hash[Symbol, Hash[Symbol, bool]],
346346
?success: Hash[Symbol, untyped] | Array[Symbol],
347347
?failure: Hash[Symbol, untyped] | Array[Symbol]
348348
) -> Module
@@ -381,7 +381,7 @@ module BCDD::Result::Expectations::Mixin
381381

382382
OPTIONS: Hash[Symbol, Module]
383383

384-
def self.options: (Symbol) -> Array[Module]
384+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
385385
end
386386
end
387387

@@ -450,7 +450,7 @@ class BCDD::Result::Context
450450

451451
OPTIONS: Hash[Symbol, Module]
452452

453-
def self.options: (Array[Symbol]) -> Array[Module]
453+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
454454
end
455455
end
456456

@@ -475,7 +475,7 @@ module BCDD::Result::Context::Expectations::Mixin
475475

476476
OPTIONS: Hash[Symbol, Module]
477477

478-
def self.options: (Symbol) -> Array[Module]
478+
def self.options: (Hash[Symbol, Hash[Symbol, bool]]) -> Array[Module]
479479
end
480480
end
481481

test/bcdd/result/and_then/with_subject/continue_instance_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class BCDD::Result::AndThenWithSubjectContinueInstanceTest < Minitest::Test
66
class Divide
7-
include BCDD::Result.mixin(config: :continue)
7+
include BCDD::Result.mixin(config: { addon: { continue: true } })
88

99
def call(arg1, arg2)
1010
validate_numbers(arg1, arg2)

test/bcdd/result/and_then/with_subject/continue_singleton_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class BCDD::Result::AndThenWithSubjectContinueSingletonTest < Minitest::Test
66
module Divide
7-
extend self, BCDD::Result.mixin(config: :continue)
7+
extend self, BCDD::Result.mixin(config: { addon: { continue: true } })
88

99
def call(arg1, arg2)
1010
validate_numbers(arg1, arg2)

test/bcdd/result/context/and_then/with_subject/continue_instance_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class BCDD::Result::Context::AndThenWithSubjectContinueInstanceTest < Minitest::Test
66
class Divide
7-
include BCDD::Result::Context.mixin(config: :continue)
7+
include BCDD::Result::Context.mixin(config: { addon: { continue: true } })
88

99
def call(arg1, arg2)
1010
validate_numbers(arg1, arg2)

0 commit comments

Comments
 (0)