Skip to content

Commit

Permalink
Merge pull request #16 from B-CDD/feature/bcdd-config
Browse files Browse the repository at this point in the history
Add BCDD::Result::Config
  • Loading branch information
serradura authored Dec 11, 2023
2 parents 97c256c + 20ef3a3 commit c18303a
Show file tree
Hide file tree
Showing 46 changed files with 1,800 additions and 349 deletions.
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

0 comments on commit c18303a

Please sign in to comment.