Skip to content

Commit c18303a

Browse files
authored
Merge pull request #16 from B-CDD/feature/bcdd-config
Add BCDD::Result::Config
2 parents 97c256c + 20ef3a3 commit c18303a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1800
-349
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ jobs:
1313
name: Ruby ${{ matrix.ruby }}
1414
strategy:
1515
matrix:
16-
ruby:
17-
- '3.2.2'
18-
- '3.1.4'
19-
- '3.0.6'
20-
- '2.7.8'
21-
16+
ruby: [2.7, 3.0, 3.1, 3.2, head]
2217
steps:
23-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
2419
- name: Set up Ruby
2520
uses: ruby/setup-ruby@v1
2621
with:
2722
ruby-version: ${{ matrix.ruby }}
2823
bundler-cache: true
29-
- name: Run the default task
30-
run: bundle exec rake
31-
- name: Run the steep check
24+
- name: Run BCDD::Result.configuration test (Minitest)
25+
run: bundle exec rake test_configuration TEST_CONFIG_FREEZING=true
26+
- name: Run tests (Minitest)
27+
run: bundle exec rake test
28+
- name: Run static code analysis (Rubocop)
29+
run: bundle exec rake rubocop
30+
- name: Run static type checking (Steep)
3231
run: bundle exec steep check
32+
if: ${{ matrix.ruby == 3.2 }}

.rubocop.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,10 @@ Minitest/MultipleAssertions:
6565

6666
Minitest/AssertEmptyLiteral:
6767
Enabled: false
68+
69+
Minitest/AssertOperator:
70+
Enabled: false
71+
72+
Naming/FileName:
73+
Exclude:
74+
- lib/bcdd-result.rb

CHANGELOG.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,122 @@
1+
- [\[Unreleased\]](#unreleased)
2+
- [Added](#added)
3+
- [Changed](#changed)
4+
- [Removed](#removed)
5+
- [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
6+
- [Added](#added-1)
7+
- [Changed](#changed-1)
8+
- [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
9+
- [Added](#added-2)
10+
- [Changed](#changed-2)
11+
- [\[0.5.0\] - 2023-10-09](#050---2023-10-09)
12+
- [Added](#added-3)
13+
- [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
14+
- [Added](#added-4)
15+
- [Changed](#changed-3)
16+
- [Removed](#removed-1)
17+
- [\[0.3.0\] - 2023-09-26](#030---2023-09-26)
18+
- [Added](#added-5)
19+
- [\[0.2.0\] - 2023-09-26](#020---2023-09-26)
20+
- [Added](#added-6)
21+
- [Removed](#removed-2)
22+
- [\[0.1.0\] - 2023-09-25](#010---2023-09-25)
23+
- [Added](#added-7)
24+
125
## [Unreleased]
226

27+
### Added
28+
29+
- Add `BCDD::Result.config`
30+
- **Feature**
31+
```ruby
32+
BCDD::Result.config.feature.options
33+
BCDD::Result.config.feature.enabled?(:expectations)
34+
BCDD::Result.config.feature.enable!(:expectations)
35+
BCDD::Result.config.feature.disable!(:expectations)
36+
```
37+
- **Default Add-ons**
38+
```ruby
39+
BCDD::Result.config.addon.options
40+
BCDD::Result.config.addon.enabled?(:continue)
41+
BCDD::Result.config.addon.enable!(:continue)
42+
BCDD::Result.config.addon.disable!(:continue)
43+
```
44+
- **Pattern matching**
45+
```ruby
46+
BCDD::Result.config.pattern_matching.options
47+
BCDD::Result.config.pattern_matching.enabled?(:nil_as_valid_value_checking)
48+
BCDD::Result.config.pattern_matching.enable!(:nil_as_valid_value_checking)
49+
BCDD::Result.config.pattern_matching.disable!(:nil_as_valid_value_checking)
50+
```
51+
- **Constant Aliases**
52+
```ruby
53+
BCDD::Result.config.constant_alias.options
54+
BCDD::Result.config.constant_alias.enabled?('Result')
55+
BCDD::Result.config.constant_alias.enable!('Result')
56+
BCDD::Result.config.constant_alias.disable!('Result')
57+
```
58+
59+
- 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.
60+
```ruby
61+
BCDD::Result.configuration do |config|
62+
config.addon.enable!(:continue)
63+
64+
config.constant_alias.enable!('Result')
65+
66+
config.pattern_matching.disable!(:nil_as_valid_value_checking)
67+
68+
config.feature.disable!(:expectations) if ::Rails.env.production?
69+
end
70+
71+
BCDD::Result.config.addon.enabled?(:continue) # true
72+
BCDD::Result.config.constant_alias.enabled?('Result') # true
73+
74+
BCDD::Result.config.addon.disable!(:continue) # raises FrozenError
75+
BCDD::Result.config.constant_alias.disable!('Result') # raises FrozenError
76+
```
77+
78+
- 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.
79+
```ruby
80+
extend BCDD::Result::Expectations.mixin(
81+
config: {
82+
addon: { continue: false },
83+
pattern_matching: { nil_as_valid_value_checking: true },
84+
},
85+
success: {
86+
numbers: ->(value) { value => [Numeric, Numeric] },
87+
division_completed: Numeric
88+
},
89+
failure: {
90+
invalid_arg: String,
91+
division_by_zero: String
92+
}
93+
)
94+
```
95+
96+
### Changed
97+
98+
- **(BREAKING)** Replace `BCDD::Result::Contract.nil_as_valid_value_checking!` with `BCDD::Result::Config.pattern_matching.enable!(:nil_as_valid_value_checking)`.
99+
100+
- **(BREAKING)** Replace `BCDD::Result::Contract.nil_as_valid_value_checking?` with `BCDD::Result::Config.pattern_matching.enabled?(:nil_as_valid_value_checking)`.
101+
102+
- **(BREAKING)** Replace `mixin(with:)` with `mixin(config:)` keyword argument.
103+
104+
- **(BREAKING)** Change the addons definition.
105+
- **From**
106+
```ruby
107+
BCDD::Result.mixin(with: :Continue)
108+
BCDD::Result.mixin(with: [:Continue])
109+
```
110+
- **To**
111+
```ruby
112+
BCDD::Result.mixin(config: { addon: { continue: true } })
113+
```
114+
- 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`)
115+
116+
### Removed
117+
118+
- **(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')`.
119+
3120
## [0.7.0] - 2023-10-27
4121

5122
### Added

Gemfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ source 'https://rubygems.org'
55
# Specify your gem's dependencies in bcdd-result.gemspec
66
gemspec
77

8-
gem 'rake', '~> 13.0'
8+
gem 'rake', '~> 13.1'
99

10-
gem 'minitest', '~> 5.0'
10+
gem 'minitest', '~> 5.20'
11+
gem 'mocha', '~> 2.1', require: false
1112

12-
gem 'rubocop', '~> 1.21'
13-
gem 'rubocop-minitest', '~> 0.31.1'
13+
gem 'rubocop', '~> 1.58', '>= 1.58.0'
14+
gem 'rubocop-minitest', '~> 0.33.0'
1415
gem 'rubocop-performance', '~> 1.19', '>= 1.19.1'
1516
gem 'rubocop-rake', '~> 0.6.0'
1617

1718
gem 'simplecov', '~> 0.22.0', require: false
1819

19-
gem 'steep', '~> 1.5', '>= 1.5.3', require: false
20+
gem 'steep', '~> 1.6', require: false if RUBY_VERSION >= '3.0'

0 commit comments

Comments
 (0)