<commit_before>module MandrillActionMailer
  class DeliveryHandler
    attr_accessor :settings

    MIME_TYPES = {
      :html => "text/html",
      :text => "text/plain"
    }.freeze

    def initialize(options={})
      self.settings = { :track_opens => MandrillActionMailer.config.track_opens, :track_clicks => MandrillActionMailer.config.track_clicks }.merge(options)
    end

    def deliver!(message)
      message_payload = {
        :track_opens => settings[:track_opens],
        :track_clicks => settings[:track_clicks],
        :subject => message.subject,
        :from_name => (message[:from_name].nil? || message[:from_name].value.blank?) ? nil : message[:from_name].value,
        :from_email => message.from.first,
        :to => message.to.map { |email| { :email => email, :name => email } },
        :headers => { 'Reply-To' => message.reply_to.blank? ? nil : message.reply_to },
        :bcc_address  => message.bcc ? message.bcc.first : nil,
      }

      MIME_TYPES.keys.each do |format|
        content = content_for(message, format)
        message_payload[format] = content.to_s if content
      end

      MandrillActionMailer.client.messages.send(message_payload)
    end

    private

    def content_for(message, format)
      content = message.send(:"#{format.to_s}_part")
      content = content.body if content && content.respond_to?(:body)

      content ||= message.body if message.mime_type == MIME_TYPES.fetch(format)
      content
    end
  end
end
<commit_msg>Splitting up the payload hash creation a bit to avoid ternaries everywhere<commit_after>module MandrillActionMailer
  class DeliveryHandler
    attr_accessor :settings

    MIME_TYPES = {
      :html => "text/html",
      :text => "text/plain"
    }.freeze

    def initialize(options={})
      self.settings = { :track_opens => MandrillActionMailer.config.track_opens, :track_clicks => MandrillActionMailer.config.track_clicks }.merge(options)
    end

    def deliver!(message)
      message_payload = {
        :track_opens => settings[:track_opens],
        :track_clicks => settings[:track_clicks],
        :subject => message.subject,
        :from_email => message.from.first,
        :to => message.to.map { |email| { :email => email, :name => email } },
      }

      if !(message[:from_name].nil? || message[:from_name].value.blank?)
        message_payload[:from_name] = message[:from_name].value
      end

      if !message.reply_to.blank?
        message_payload[:headers] ||= {}
        message_payload[:headers]['Reply-To'] = message.reply_to.first
      end

      if !message.bcc.blank?
        message_payload[:bcc_address] = message.bcc.first
      end

      MIME_TYPES.keys.each do |format|
        content = content_for(message, format)
        message_payload[format] = content.to_s unless content.blank?
      end

      MandrillActionMailer.client.messages.send(message_payload)
    end

    private

    def content_for(message, format)
      content = message.send(:"#{format.to_s}_part")
      content = content.body if content && content.respond_to?(:body)

      content ||= message.body if message.mime_type == MIME_TYPES.fetch(format)
      content
    end
  end
end

{'fraction_non_alphanumeric': 0.1244138793372929, 'fraction_numerical': 0.0, 'mean_word_length': 3.005006257822278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1076642', 'n_tokens_mistral': 1000, 'n_tokens_neox': 975, 'n_words': 186}