diff --git a/.rubocop.yml b/.rubocop.yml index b09d043..5b7544e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -15,10 +15,6 @@ AllCops: Gemspec/RequireMFA: Enabled: false -Lint/DuplicateMethods: - Exclude: - - lib/active_outbox/configuration.rb - Metrics/MethodLength: Max: 12 diff --git a/Gemfile.lock b/Gemfile.lock index 7ff946d..298d21e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,8 @@ PATH remote: . specs: - active_outbox (0.0.3) + active_outbox (0.0.4) + dry-configurable (~> 1.0) rails (~> 6.1) GEM @@ -80,6 +81,12 @@ GEM date (3.3.3) diff-lcs (1.5.0) docile (1.4.0) + dry-configurable (1.1.0) + dry-core (~> 1.0, < 2) + zeitwerk (~> 2.6) + dry-core (1.0.1) + concurrent-ruby (~> 1.0) + zeitwerk (~> 2.6) erubi (1.12.0) globalid (1.2.1) activesupport (>= 6.1) diff --git a/active_outbox.gemspec b/active_outbox.gemspec index 2dad5f3..fd0d716 100644 --- a/active_outbox.gemspec +++ b/active_outbox.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |spec| spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*', 'lib/active_outbox.rb'] spec.name = 'active_outbox' spec.summary = 'A Transactional Outbox implementation for ActiveRecord' - spec.version = '0.0.3' + spec.version = '0.0.4' spec.email = 'guillermoaguirre1@gmail.com' spec.executables = ['outbox'] @@ -13,5 +13,6 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.required_ruby_version = '>= 3.0' + spec.add_dependency 'dry-configurable', '~> 1.0' spec.add_dependency 'rails', '~> 6.1' end diff --git a/lib/active_outbox.rb b/lib/active_outbox.rb index 763626f..4f9f81b 100644 --- a/lib/active_outbox.rb +++ b/lib/active_outbox.rb @@ -1,8 +1,15 @@ # frozen_string_literal: true require 'active_outbox/adapter_helper' -require 'active_outbox/configuration' require 'active_outbox/errors' require 'active_outbox/generators/active_outbox_generator' require 'active_outbox/outboxable' require 'active_outbox/railtie' if defined?(Rails::Railtie) +require 'dry-configurable' + +module ActiveOutbox + extend Dry::Configurable + + setting :adapter, default: :sqlite + setting :outbox_mapping, default: {} +end diff --git a/lib/active_outbox/configuration.rb b/lib/active_outbox/configuration.rb deleted file mode 100644 index 9a4e5c2..0000000 --- a/lib/active_outbox/configuration.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module ActiveOutbox - class << self - attr_accessor :configuration - - def configuration - @configuration ||= ActiveOutbox::Configuration.new - end - - def reset - @configuration = ActiveOutbox::Configuration.new - end - - def configure - yield(configuration) - end - end - - class Configuration - attr_accessor :adapter, :outbox_mapping - - def initialize - @adapter = :sqlite - @outbox_mapping = {} - end - end -end diff --git a/lib/active_outbox/outboxable.rb b/lib/active_outbox/outboxable.rb index 16e79d9..cfb6c3f 100644 --- a/lib/active_outbox/outboxable.rb +++ b/lib/active_outbox/outboxable.rb @@ -71,11 +71,11 @@ def outbox_model_name! def namespace_outbox_mapping namespace = self.class.name.split('/').first - ActiveOutbox.configuration.outbox_mapping[namespace&.underscore] + ActiveOutbox.config.outbox_mapping[namespace&.underscore] end def default_outbox_mapping - ActiveOutbox.configuration.outbox_mapping['default'] + ActiveOutbox.config.outbox_mapping['default'] end def handle_outbox_errors(outbox) diff --git a/spec/lib/active_outbox/outboxable_spec.rb b/spec/lib/active_outbox/outboxable_spec.rb index e51daa6..cf26c7b 100644 --- a/spec/lib/active_outbox/outboxable_spec.rb +++ b/spec/lib/active_outbox/outboxable_spec.rb @@ -59,7 +59,7 @@ context 'when record is created' do context 'when the ActiveOutbox configuration is not set' do before do - allow(ActiveOutbox.configuration).to receive(:outbox_mapping).and_return({ 'default' => nil }) + allow(ActiveOutbox.config).to receive(:outbox_mapping).and_return({ 'default' => nil }) end include_examples 'raises an error and does not create neither the record nor the outbox record',