Module: LogStruct::Integrations::ActionMailer::MetadataCollection

Extended by:
T::Sig
Defined in:
lib/log_struct/integrations/action_mailer/metadata_collection.rb

Overview

Handles collection of metadata for email logging

Class Method Summary collapse

Class Method Details

.add_context_metadata(mailer, log_data) ⇒ void

This method returns an undefined value.

Add context metadata to log data

Parameters:

  • mailer (T.untyped)
  • log_data (Hash{Symbol => T.untyped})


25
26
27
28
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 25

def self.(mailer, log_data)
  # Add account ID information if available (but not user email)
  extract_ids_to_log_data(mailer, log_data)
end

.add_message_metadata(mailer, log_data) ⇒ void

This method returns an undefined value.

Add message-specific metadata to log data

Parameters:

  • mailer (T.untyped)
  • log_data (Hash{Symbol => T.untyped})


12
13
14
15
16
17
18
19
20
21
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 12

def self.(mailer, log_data)
  message = mailer.respond_to?(:message) ? mailer.message : nil

  # Add attachment count if message is available
  log_data[:attachment_count] = if message
    message.attachments&.count || 0
  else
    0
  end
end

.extract_ids_to_log_data(mailer, log_data) ⇒ void

This method returns an undefined value.

Parameters:

  • mailer (T.untyped)
  • log_data (Hash{Symbol => T.untyped})


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/log_struct/integrations/action_mailer/metadata_collection.rb', line 31

def self.extract_ids_to_log_data(mailer, log_data)
  # Use configured ID mapping from LogStruct configuration
  id_mapping = LogStruct.config.integrations.actionmailer_id_mapping

  id_mapping.each do |ivar_name, log_key|
    ivar = :"@#{ivar_name}"
    next unless mailer.instance_variable_defined?(ivar)

    obj = mailer.instance_variable_get(ivar)
    log_data[log_key] = obj.id if obj.respond_to?(:id)
  end
end