Sha256: 3771f68fda0181c60630ec093662b27678c4c0c71cd561400975364da57f6cd5

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Emailbutler
  module Mailers
    module Helpers
      extend ActiveSupport::Concern

      included do
        after_action :save_emailbutler_message
      end

      private

      def process_action(*args)
        build_emailbutler_message(args)

        super
      end

      def build_emailbutler_message(args)
        @message = Emailbutler.build_message(
          mailer: self.class.to_s,
          action: action_name,
          params: serialize_params(mailer_params: params, action_params: args[1..])
        )
      end

      def serialize_params(value)
        return value.map { |element| serialize_params(element) } if value.is_a?(Array)
        return value.transform_values { |element| serialize_params(element) } if value.is_a?(Hash)
        return value.to_global_id.to_s if value.respond_to?(:to_global_id)

        value
      end

      def save_emailbutler_message
        Emailbutler.set_message_attribute(@message, :send_to, mail.to)
        Emailbutler.save_message(@message)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
emailbutler-0.2.3 lib/emailbutler/mailers/helpers.rb
emailbutler-0.2.2 lib/emailbutler/mailers/helpers.rb