Class: Slack::Notifier::PayloadMiddleware::FormatAttachments

Inherits:
Base
  • Object
show all
Defined in:
lib/slack-notifier/payload_middleware/format_attachments.rb

Instance Attribute Summary

Attributes inherited from Base

#notifier, #options

Instance Method Summary collapse

Methods inherited from Base

default_opts, #initialize, middleware_name, options

Constructor Details

This class inherits a constructor from Slack::Notifier::PayloadMiddleware::Base

Instance Method Details

#call(payload = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/slack-notifier/payload_middleware/format_attachments.rb', line 11

def call payload={}
  payload = payload.dup
  attachments = payload.delete(:attachments)
  attachments ||= payload.delete("attachments")

  attachments = wrap_array(attachments).map do |attachment|
    ["text", :text].each do |key|
      if attachment.key?(key)
        attachment[key] = Util::LinkFormatter.format(attachment[key], options)
      end
    end

    attachment
  end

  payload[:attachments] = attachments if attachments && !attachments.empty?
  payload
end