Skip to content

Commit

Permalink
Rename Events to ActiveOutbox::Events to avoid conflicts. Bump to 0.2…
Browse files Browse the repository at this point in the history
….0 (#22)

* Rename Events to ActiveOutboxEvents to avoid conflicts.

* Issue was raised that the Events const name was pretty common and this could cause conflicts.

* Added false in const_defined so it won't lookup to ancestors.

* Change spec definition ordering to make suite fail

* Move CRUD specs to its own file

* Namespace events constant with ActiveOutbox

* Bump version to 0.2.0

* Cleanup Rubocop constraints
  • Loading branch information
guillermoap authored Apr 25, 2024
1 parent 53caa02 commit 65a81f9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ RSpec/MultipleMemoizedHelpers:
RSpec/NestedGroups:
Max: 7

RSpec/FilePath:
Exclude:
- spec/lib/active_outbox/outboxable/*

RSpec/SpecFilePathFormat:
Exclude:
- spec/lib/active_outbox/outboxable/*

Style/Documentation:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
active_outbox (0.1.4)
active_outbox (0.2.0)
dry-configurable (~> 1.0)
rails (>= 6.1)

Expand Down
2 changes: 1 addition & 1 deletion active_outbox.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.4'
spec.version = '0.2.0'

spec.email = 'guillermoaguirre1@gmail.com'
spec.executables = ['outbox']
Expand Down
13 changes: 9 additions & 4 deletions lib/active_outbox/outboxable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ module Outboxable
*namespace, klass = name.underscore.upcase.split('/')
namespace = namespace.reverse.join('.')

module_parent.const_set('Events', Module.new) unless module_parent.const_defined?('Events')
module_parent.const_set('ActiveOutbox', Module.new) unless module_parent.const_defined?('ActiveOutbox', false)

unless module_parent::ActiveOutbox.const_defined?('Events', false)
module_parent::ActiveOutbox.const_set('Events', Module.new)
end

{ create: 'CREATED', update: 'UPDATED', destroy: 'DESTROYED' }.each do |key, value|
const_name = "#{klass}_#{value}"

unless module_parent::Events.const_defined?(const_name)
module_parent::Events.const_set(const_name, "#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}")
unless module_parent::ActiveOutbox::Events.const_defined?(const_name)
module_parent::ActiveOutbox::Events.const_set(const_name,
"#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}")
end

event_name = module_parent::Events.const_get(const_name)
event_name = module_parent::ActiveOutbox::Events.const_get(const_name)

send("after_#{key}") { create_outbox!(key, event_name) }
end
Expand Down
File renamed without changes.
27 changes: 15 additions & 12 deletions spec/support/outbox_models.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# frozen_string_literal: true

# NOTICE:
# Class definition ordering matters in this file. Do not change unless deemed necessary

Object.const_set('Uuid', Module.new)

Outbox = Class.new(ActiveRecord::Base) do
def self.name
'Outbox'
end

validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event
end

Uuid::Outbox = Class.new(ActiveRecord::Base) do
def self.name
'Uuid::Outbox'
Expand All @@ -14,12 +25,13 @@ def self.table_name
validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event
end

Outbox = Class.new(ActiveRecord::Base) do
FakeModel = Class.new(ActiveRecord::Base) do
def self.name
'Outbox'
'FakeModel'
end

validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event
validates_presence_of :test_field
include ActiveOutbox::Outboxable
end

Uuid::FakeModel = Class.new(ActiveRecord::Base) do
Expand All @@ -35,15 +47,6 @@ def self.table_name
include ActiveOutbox::Outboxable
end

FakeModel = Class.new(ActiveRecord::Base) do
def self.name
'FakeModel'
end

validates_presence_of :test_field
include ActiveOutbox::Outboxable
end

def create_migrations
id_migrations
uuid_migrations
Expand Down

0 comments on commit 65a81f9

Please sign in to comment.