Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
mwolman committed Oct 3, 2023
1 parent f2d73e1 commit f3d1a6f
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/active_outbox/outboxable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f3d1a6f

Please sign in to comment.