Sha256: fe05c5571352bbc6f805856892e6dc72bb42225092ff1f7d8e6b31a71d678699

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Emailbutler
  module Helpers
    private

    def resend_message_with_mailer(message)
      params = message.params

      mailer = message.mailer.constantize
      mailer = mailer.with(serialize(params['mailer_params'])) if params['mailer_params'].present?
      mailer = mailer.method(message.action)
      mailer = params['action_params'] ? mailer.call(*serialize(params['action_params'])) : mailer.call
      mailer.deliver_now
    end

    def serialize(value, reverse=true)
      return value.map { |element| serialize(element, reverse) } if value.is_a?(Array)
      return value.transform_values { |element| serialize(element, reverse) } if value.is_a?(Hash)

      reverse ? deserialize_value(value) : serialize_value(value)
    end

    def serialize_value(value)
      return value.to_global_id.to_s if value.respond_to?(:to_global_id)
      return if value.is_a?(String) && !value&.valid_encoding?

      value
    end

    def deserialize_value(value)
      return GlobalID::Locator.locate(value) if value.is_a?(String) && value.starts_with?('gid://')

      value
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
emailbutler-0.8.8 lib/emailbutler/helpers.rb
emailbutler-0.8.7 lib/emailbutler/helpers.rb
emailbutler-0.8.6 lib/emailbutler/helpers.rb
emailbutler-0.8.5 lib/emailbutler/helpers.rb
emailbutler-0.8.4 lib/emailbutler/helpers.rb
emailbutler-0.8.3 lib/emailbutler/helpers.rb
emailbutler-0.8.2 lib/emailbutler/helpers.rb
emailbutler-0.8.1 lib/emailbutler/helpers.rb
emailbutler-0.7.6 lib/emailbutler/helpers.rb
emailbutler-0.7.5 lib/emailbutler/helpers.rb