Skip to content

Commit

Permalink
Rename Events to ActiveOutboxEvents to avoid conflicts.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
guillermoap committed Mar 8, 2024
1 parent 53caa02 commit 044d958
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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
8 changes: 4 additions & 4 deletions lib/active_outbox/outboxable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ 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('ActiveOutboxEvents', Module.new) unless module_parent.const_defined?('ActiveOutboxEvents', false)

{ 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::ActiveOutboxEvents.const_defined?(const_name)
module_parent::ActiveOutboxEvents.const_set(const_name, "#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}")
end

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

send("after_#{key}") { create_outbox!(key, event_name) }
end
Expand Down

0 comments on commit 044d958

Please sign in to comment.