From f3d1a6f0c15957510af1a44d2c949cbda8e2a413 Mon Sep 17 00:00:00 2001 From: Micaela Wolman Date: Tue, 3 Oct 2023 16:10:32 -0300 Subject: [PATCH] Apply suggestions from code review --- lib/active_outbox/outboxable.rb | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/active_outbox/outboxable.rb b/lib/active_outbox/outboxable.rb index e1840d1..16e79d9 100644 --- a/lib/active_outbox/outboxable.rb +++ b/lib/active_outbox/outboxable.rb @@ -40,7 +40,6 @@ def assign_outbox_event(options) end def create_outbox!(action, event_name) - outbox_model = determine_outbox_model outbox = outbox_model.new( aggregate: self.class.name, aggregate_identifier: try(:identifier) || id, @@ -54,22 +53,19 @@ def create_outbox!(action, event_name) outbox.save! end - def determine_outbox_model - unless self.class.module_parent.const_defined?('OUTBOX_MODEL') - outbox_model_name = determine_outbox_model_name - outbox_model = outbox_model_name.safe_constantize - self.class.module_parent.const_set('OUTBOX_MODEL', outbox_model) - end + def outbox_model + module_parent = self.class.module_parent - self.class.module_parent.const_get('OUTBOX_MODEL') - end + unless module_parent.const_defined?('OUTBOX_MODEL') + outbox_model = outbox_model_name!.safe_constantize + module_parent.const_set('OUTBOX_MODEL', outbox_model) + end - def determine_outbox_model_name - outbox_model_name_from_config || raise(OutboxClassNotFoundError) + module_parent.const_get('OUTBOX_MODEL') end - def outbox_model_name_from_config - namespace_outbox_mapping || default_outbox_mapping + def outbox_model_name! + namespace_outbox_mapping || default_outbox_mapping || raise(OutboxClassNotFoundError) end def namespace_outbox_mapping @@ -90,7 +86,7 @@ def handle_outbox_errors(outbox) def formatted_payload(action) payload = construct_payload(action) - ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql' ? payload : payload.to_json + AdapterHelper.postgres? ? payload : payload.to_json end def construct_payload(action)