Skip to content

Commit 8c408fe

Browse files
Fixes Rubocop Offenses
1 parent 918d4f9 commit 8c408fe

15 files changed

+62
-58
lines changed

.rubocop.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ AllCops:
55
SuggestExtensions: false
66
Layout/SpaceBeforeBrackets: # (new in 1.7)
77
Enabled: true
8-
Layout/LineLength:
8+
Layout/LineLength:
99
Max: 350
1010
Lint/AmbiguousAssignment: # (new in 1.7)
1111
Enabled: true
@@ -110,4 +110,8 @@ Metrics/MethodLength:
110110
Metrics/CyclomaticComplexity:
111111
Max: 15
112112
Metrics/PerceivedComplexity:
113-
Max: 15
113+
Max: 15
114+
Lint/DuplicateMethods: # Disables duplicate methods warning
115+
Enabled: false
116+
Gemspec/RequiredRubyVersion: # Disables required ruby version warning
117+
Enabled: false

Gemfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# frozen_string_literal: true
22

3-
source "https://rubygems.org"
3+
source 'https://rubygems.org'
44

55
# Specify your gem's dependencies in outboxable.gemspec
66
gemspec
77

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

10-
gem "rspec", "~> 3.0"
10+
gem 'rspec', '~> 3.0'
1111

12-
gem "rubocop-rails", "~> 2.18"
12+
gem 'rubocop-rails', '~> 2.18'
1313

1414
gem 'sidekiq-cron', '~> 1.9'
1515

Rakefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
22

3-
require "bundler/gem_tasks"
4-
require "rspec/core/rake_task"
3+
require 'bundler/gem_tasks'
4+
require 'rspec/core/rake_task'
55

66
RSpec::Core::RakeTask.new(:spec)
77

8-
require "rubocop/rake_task"
8+
require 'rubocop/rake_task'
99

1010
RuboCop::RakeTask.new
1111

lib/generators/outboxable/install_generator.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Outboxable
22
class InstallGenerator < Rails::Generators::Base
33
include Rails::Generators::Migration
44

5-
source_root File.expand_path('../../../templates', __FILE__)
5+
source_root File.expand_path('../../templates', __dir__)
66

77
# Copy initializer into user app
88
def copy_initializer
@@ -11,26 +11,26 @@ def copy_initializer
1111

1212
# Copy user information (model & Migrations) into user app
1313
def create_user_model
14-
target_path = "app/models/outbox.rb"
15-
unless File.exist?(File.join(Rails.root, target_path))
16-
template("outbox.rb", target_path)
14+
target_path = 'app/models/outbox.rb'
15+
if Rails.root.join(target_path).exist?
16+
say_status('skipped', 'Model outbox already exists')
1717
else
18-
say_status('skipped', "Model outbox already exists")
18+
template('outbox.rb', target_path)
1919
end
2020
end
2121

2222
# Copy migrations
2323
def copy_migrations
24-
if self.class.migration_exists?('db/migrate', "create_outboxable_outboxes")
25-
say_status('skipped', "Migration create_outboxable_outboxes already exists")
24+
if self.class.migration_exists?('db/migrate', 'create_outboxable_outboxes')
25+
say_status('skipped', 'Migration create_outboxable_outboxes already exists')
2626
else
27-
migration_template('create_outboxable_outboxes.rb', "db/migrate/create_outboxable_outboxes.rb")
27+
migration_template('create_outboxable_outboxes.rb', 'db/migrate/create_outboxable_outboxes.rb')
2828
end
2929
end
3030

3131
# Use to assign migration time otherwise generator will error
32-
def self.next_migration_number(dir)
33-
Time.now.utc.strftime("%Y%m%d%H%M%S")
32+
def self.next_migration_number(_dir)
33+
Time.now.utc.strftime('%Y%m%d%H%M%S')
3434
end
3535
end
3636
end

lib/outboxable.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "outboxable/version"
3+
require_relative 'outboxable/version'
44

55
require 'outboxable/worker'
66
require 'outboxable/publishing_manager'
@@ -10,7 +10,6 @@
1010
require 'outboxable/rabbitmq/publisher'
1111
require 'active_support'
1212

13-
1413
module Outboxable
1514
class Error < StandardError; end
1615

@@ -22,7 +21,7 @@ class Error < StandardError; end
2221

2322
has_many :outboxes, as: :outboxable, autosave: false
2423

25-
def instantiate_outbox(routing_key: )
24+
def instantiate_outbox(routing_key:)
2625
outboxes.new(
2726
routing_key:,
2827
exchange: Outboxable.configuration.rabbitmq_event_bus_exchange,

lib/outboxable/configuration.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Configuration
1212
ALLOWED_MESSAGE_BROKERS = %i[rabbitmq].freeze
1313
ALLOWED_ORMS = %i[activerecord].freeze
1414

15-
attr_accessor :rabbitmq_host,
15+
attr_accessor :rabbitmq_host,
1616
:rabbitmq_port,
1717
:rabbitmq_user,
1818
:rabbitmq_password,
@@ -31,7 +31,7 @@ def initialize
3131
Sidekiq::Options[:cron_poll_interval] = 5
3232

3333
# Create the cron job for the polling publisher
34-
Sidekiq::Cron::Job.create(name: 'OutboxablePollingPublisher', cron: '*/5 * * * * *', class: 'Outboxable::PollingPublisherWorker')
34+
Sidekiq::Cron::Job.create(name: 'OutboxablePollingPublisher', cron: '*/5 * * * * *', class: 'Outboxable::PollingPublisherWorker')
3535
end
3636

3737
def message_broker=(message_broker)

lib/outboxable/polling_publisher_worker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ def perform
1111
end
1212
end
1313
end
14-
end
14+
end

lib/outboxable/rabbitmq/publisher.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@ class Publisher
44
def initialize(resource:)
55
@resource = resource
66
end
7-
7+
88
def to_envelope(resource:)
99
# throw not implemented method error
10-
raise NotImplementedError, "Please implement the to_envelope method in your own module"
10+
raise NotImplementedError, 'Please implement the to_envelope method in your own module'
1111
end
12-
12+
1313
def publish
1414
confirmed = nil
15-
15+
1616
Outboxable::Connection.instance.channel.with do |channel|
1717
channel.confirm_select
18-
18+
1919
# Declare a exchange
2020
exchange = channel.topic(@resource.exchange, durable: true)
21-
21+
2222
# Publish the CloudEvent resource to the exchange
2323
exchange.publish(to_envelope(resource: @resource), routing_key: @resource.routing_key, headers: @resource.try(:headers) || {})
24-
24+
2525
# Wait for confirmation
2626
confirmed = channel.wait_for_confirms
2727
end
28-
28+
2929
return unless confirmed
30-
30+
3131
@resource.reload
3232
@resource.increment_attempt
3333
@resource.update(status: :published, retry_at: nil)
3434
end
3535
end
3636
end
37-
end
37+
end

lib/outboxable/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Outboxable
4-
VERSION = "0.1.1"
4+
VERSION = '0.1.1'
55
end

lib/templates/create_outboxable_outboxes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def change
1717

1818
t.integer :size, null: false, default: 0
1919

20-
t.references :outboxable, polymorphic: true, null: true
20+
t.references :outboxable, polymorphic: true, null: true
2121

2222
t.timestamps
2323
end

lib/templates/initializer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This monkey patch allows you to customize the message format that you publish to your broker.
1+
# This monkey patch allows you to customize the message format that you publish to your broker.
22
# By default, Outboxable publishes a CloudEvent message to your broker.
33
module Outboxable
44
module RabbitMq

lib/templates/outbox.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def publish
2929
def check_publishing
3030
self.allow_publish = false if published?
3131
end
32-
end
32+
end

outboxable.gemspec

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# frozen_string_literal: true
22

3-
require_relative "lib/outboxable/version"
3+
require_relative 'lib/outboxable/version'
44

55
Gem::Specification.new do |spec|
6-
spec.name = "outboxable"
6+
spec.name = 'outboxable'
77
spec.version = Outboxable::VERSION
8-
spec.authors = ["Brusk Awat"]
9-
spec.email = ["[email protected]"]
8+
spec.authors = ['Brusk Awat']
9+
spec.email = ['[email protected]']
1010

11-
spec.summary = "An opiniated Gem for Rails applications to implement the transactional outbox pattern."
12-
spec.description = "The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord."
13-
spec.homepage = "https://github.com/broosk1993/outboxable"
14-
spec.license = "MIT"
15-
spec.required_ruby_version = ">= 2.6.0"
11+
spec.summary = 'An opiniated Gem for Rails applications to implement the transactional outbox pattern.'
12+
spec.description = 'The Outboxable Gem is tailored for Rails applications to implement the transactional outbox pattern. It currently only supports ActiveRecord.'
13+
spec.homepage = 'https://github.com/broosk1993/outboxable'
14+
spec.license = 'MIT'
15+
spec.required_ruby_version = '>= 2.6.0'
1616

1717
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
1818

19-
spec.metadata["homepage_uri"] = spec.homepage
20-
spec.metadata["source_code_uri"] = "https://github.com/broosk1993/outboxable"
21-
spec.metadata["changelog_uri"] = "https://github.com/broosk1993/outboxable/blob/main/CHANGELOG.md"
19+
spec.metadata['homepage_uri'] = spec.homepage
20+
spec.metadata['source_code_uri'] = 'https://github.com/broosk1993/outboxable'
21+
spec.metadata['changelog_uri'] = 'https://github.com/broosk1993/outboxable/blob/main/CHANGELOG.md'
2222

2323
# Specify which files should be added to the gem when it is released.
2424
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -27,10 +27,11 @@ Gem::Specification.new do |spec|
2727
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
2828
end
2929
end
30-
spec.bindir = "exe"
30+
spec.bindir = 'exe'
3131
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32-
spec.require_paths = ["lib"]
33-
32+
spec.require_paths = ['lib']
33+
3434
spec.add_dependency 'bunny', '>= 2.19.0'
3535
spec.add_dependency 'connection_pool', '~> 2.3.0'
36+
spec.metadata['rubygems_mfa_required'] = 'true'
3637
end

spec/outboxable_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# frozen_string_literal: true
22

33
RSpec.describe Outboxable do
4-
it "has a version number" do
4+
it 'has a version number' do
55
expect(Outboxable::VERSION).not_to be nil
66
end
77

8-
it "does something useful" do
8+
it 'does something useful' do
99
expect(true).to eq(true)
1010
end
1111
end

spec/spec_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# frozen_string_literal: true
22

3-
require "outboxable"
3+
require 'outboxable'
44

55
RSpec.configure do |config|
66
# Enable flags like --only-failures and --next-failure
7-
config.example_status_persistence_file_path = ".rspec_status"
7+
config.example_status_persistence_file_path = '.rspec_status'
88

99
# Disable RSpec exposing methods globally on `Module` and `main`
1010
config.disable_monkey_patching!

0 commit comments

Comments
 (0)