Skip to content

Commit

Permalink
Use a null object to avoid checks to @instance
Browse files Browse the repository at this point in the history
In the `ConnectionManagement` class, a pattern we see a lot is the
following one:
```ruby
if @instance
  # do something
else
  # do something else
end
```

This patch aims to simplify this a bit by introducing a null object
(`NullInstance`) which will be returned when `@instance` is null. This
way the rest of the code doesn’t care with which object it’s working and
has just to call the expected methods on it.
  • Loading branch information
Flink committed Mar 12, 2024
1 parent ed26f6a commit 38f0591
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 188 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["3.0", "3.1", "3.2"]
rails: ["6.0", "6.1", "7.0", "edge"]
ruby: ["3.0", "3.1", "3.2", "3.3"]
rails: ["6.1", "7.0", "7.1", "edge"]
ok_to_fail: [""]
exclude:
- ruby: "3.0"
rails: "edge"
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ AllCops:
Exclude:
- gemfiles/vendor/bundle/**/*
- vendor/bundle/**/*

Discourse/Plugins:
Enabled: false
12 changes: 12 additions & 0 deletions gemfiles/rails_7.1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
source 'https://rubygems.org'

group :test do
gem 'activerecord', '~> 7.1.0'
gem 'railties', '~> 7.1.0'
gem 'rspec'
gem 'sqlite3', '~> 1.4'
gem 'byebug'
gem 'rubocop'
gem 'rubocop-discourse'
end
Loading

0 comments on commit 38f0591

Please sign in to comment.