Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BCDD::Result::Config #16

Merged
merged 30 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f7fd6b8
Add BCDD::Result::Config
serradura Nov 6, 2023
fd8dcbd
Add BCDD::Result.config and configure methods
serradura Nov 6, 2023
f6556e6
Refactor lib/result with BCDD::Result.config
serradura Nov 6, 2023
3be3c3e
Add BCDD::Result.config.pattern_matching
serradura Nov 6, 2023
aab0e53
Add BCDD::Result::Config::Switcher
serradura Nov 7, 2023
6779e14
Refactor BCDD::Result::Config
serradura Nov 7, 2023
bbb4cab
Replace BCDD::Result.config with BCDD::Result::Config
serradura Nov 7, 2023
9e4989f
Replace `mixin(with:)` with `mixin(config:)` keyword argument
serradura Nov 7, 2023
37d6832
Refactor expectations
serradura Nov 7, 2023
65c80ae
Refactor result and result context mixins
serradura Nov 7, 2023
1c137f1
Allow using a hash to configure addons
serradura Nov 7, 2023
ba888a8
Put back BCDD::Result.config
serradura Nov 8, 2023
166b82d
Improve BCDD::Result::Config
serradura Nov 8, 2023
3a159af
Add BCDD::Result::Config#addon
serradura Nov 8, 2023
8689802
Add BCDD::Config::Options
serradura Nov 8, 2023
41e18fa
Change addons definition (mixin + config)
serradura Nov 8, 2023
b879270
Add BCDD::Result::Config#feature
serradura Nov 8, 2023
fab3203
Allow toggle expectations via configuration
serradura Nov 8, 2023
b02935f
Simplify BCDD::Config::Options
serradura Nov 8, 2023
30afe8a
Allow expectations to receive pattern matching config
serradura Nov 8, 2023
4df8f64
Add lib/bcdd-result.rb
serradura Nov 30, 2023
aae4a13
Update gems and add mock
serradura Dec 11, 2023
5abc27a
Test BCDD::Result::Config
serradura Dec 11, 2023
f1cf766
Update .rubocop.yml
serradura Dec 11, 2023
99929e6
Add rake test_configuration
serradura Dec 11, 2023
d3f36d6
Update .github/workflows/main.yml
serradura Dec 11, 2023
9cf13d3
Fix README.md content
serradura Dec 11, 2023
eee8fa2
Update CHANGELOG.md
serradura Dec 11, 2023
160ac4d
Update README.md
serradura Dec 11, 2023
20ef3a3
Update bcdd-result.gemspec
serradura Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ jobs:
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.2.2'
- '3.1.4'
- '3.0.6'
- '2.7.8'

ruby: [2.7, 3.0, 3.1, 3.2, head]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
- name: Run the steep check
- name: Run BCDD::Result.configuration test (Minitest)
run: bundle exec rake test_configuration TEST_CONFIG_FREEZING=true
- name: Run tests (Minitest)
run: bundle exec rake test
- name: Run static code analysis (Rubocop)
run: bundle exec rake rubocop
- name: Run static type checking (Steep)
run: bundle exec steep check
if: ${{ matrix.ruby == 3.2 }}
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ Minitest/MultipleAssertions:

Minitest/AssertEmptyLiteral:
Enabled: false

Minitest/AssertOperator:
Enabled: false

Naming/FileName:
Exclude:
- lib/bcdd-result.rb
117 changes: 117 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,122 @@
- [\[Unreleased\]](#unreleased)
- [Added](#added)
- [Changed](#changed)
- [Removed](#removed)
- [\[0.7.0\] - 2023-10-27](#070---2023-10-27)
- [Added](#added-1)
- [Changed](#changed-1)
- [\[0.6.0\] - 2023-10-11](#060---2023-10-11)
- [Added](#added-2)
- [Changed](#changed-2)
- [\[0.5.0\] - 2023-10-09](#050---2023-10-09)
- [Added](#added-3)
- [\[0.4.0\] - 2023-09-28](#040---2023-09-28)
- [Added](#added-4)
- [Changed](#changed-3)
- [Removed](#removed-1)
- [\[0.3.0\] - 2023-09-26](#030---2023-09-26)
- [Added](#added-5)
- [\[0.2.0\] - 2023-09-26](#020---2023-09-26)
- [Added](#added-6)
- [Removed](#removed-2)
- [\[0.1.0\] - 2023-09-25](#010---2023-09-25)
- [Added](#added-7)

## [Unreleased]

### Added

- Add `BCDD::Result.config`
- **Feature**
```ruby
BCDD::Result.config.feature.options
BCDD::Result.config.feature.enabled?(:expectations)
BCDD::Result.config.feature.enable!(:expectations)
BCDD::Result.config.feature.disable!(:expectations)
```
- **Default Add-ons**
```ruby
BCDD::Result.config.addon.options
BCDD::Result.config.addon.enabled?(:continue)
BCDD::Result.config.addon.enable!(:continue)
BCDD::Result.config.addon.disable!(:continue)
```
- **Pattern matching**
```ruby
BCDD::Result.config.pattern_matching.options
BCDD::Result.config.pattern_matching.enabled?(:nil_as_valid_value_checking)
BCDD::Result.config.pattern_matching.enable!(:nil_as_valid_value_checking)
BCDD::Result.config.pattern_matching.disable!(:nil_as_valid_value_checking)
```
- **Constant Aliases**
```ruby
BCDD::Result.config.constant_alias.options
BCDD::Result.config.constant_alias.enabled?('Result')
BCDD::Result.config.constant_alias.enable!('Result')
BCDD::Result.config.constant_alias.disable!('Result')
```

- 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.
```ruby
BCDD::Result.configuration do |config|
config.addon.enable!(:continue)

config.constant_alias.enable!('Result')

config.pattern_matching.disable!(:nil_as_valid_value_checking)

config.feature.disable!(:expectations) if ::Rails.env.production?
end

BCDD::Result.config.addon.enabled?(:continue) # true
BCDD::Result.config.constant_alias.enabled?('Result') # true

BCDD::Result.config.addon.disable!(:continue) # raises FrozenError
BCDD::Result.config.constant_alias.disable!('Result') # raises FrozenError
```

- 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.
```ruby
extend BCDD::Result::Expectations.mixin(
config: {
addon: { continue: false },
pattern_matching: { nil_as_valid_value_checking: true },
},
success: {
numbers: ->(value) { value => [Numeric, Numeric] },
division_completed: Numeric
},
failure: {
invalid_arg: String,
division_by_zero: String
}
)
```

### Changed

- **(BREAKING)** Replace `BCDD::Result::Contract.nil_as_valid_value_checking!` with `BCDD::Result::Config.pattern_matching.enable!(:nil_as_valid_value_checking)`.

- **(BREAKING)** Replace `BCDD::Result::Contract.nil_as_valid_value_checking?` with `BCDD::Result::Config.pattern_matching.enabled?(:nil_as_valid_value_checking)`.

- **(BREAKING)** Replace `mixin(with:)` with `mixin(config:)` keyword argument.

- **(BREAKING)** Change the addons definition.
- **From**
```ruby
BCDD::Result.mixin(with: :Continue)
BCDD::Result.mixin(with: [:Continue])
```
- **To**
```ruby
BCDD::Result.mixin(config: { addon: { continue: true } })
```
- 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`)

### Removed

- **(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')`.

## [0.7.0] - 2023-10-27

### Added
Expand Down
11 changes: 6 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in bcdd-result.gemspec
gemspec

gem 'rake', '~> 13.0'
gem 'rake', '~> 13.1'

gem 'minitest', '~> 5.0'
gem 'minitest', '~> 5.20'
gem 'mocha', '~> 2.1', require: false

gem 'rubocop', '~> 1.21'
gem 'rubocop-minitest', '~> 0.31.1'
gem 'rubocop', '~> 1.58', '>= 1.58.0'
gem 'rubocop-minitest', '~> 0.33.0'
gem 'rubocop-performance', '~> 1.19', '>= 1.19.1'
gem 'rubocop-rake', '~> 0.6.0'

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

gem 'steep', '~> 1.5', '>= 1.5.3', require: false
gem 'steep', '~> 1.6', require: false if RUBY_VERSION >= '3.0'
Loading