Sha256: f15b96f1d7420ac672a5f2dcabe32c1a4dd0a237fed2c464ca428dfddd3aa2df

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'slackistrano/capistrano'

module Capistrano
  module Wearerequired
    class SlackistranoMessagingColors < Slackistrano::Messaging::Base

      def initialize(env: nil, team: nil, channel: nil, token: nil, webhook: nil, icon_url: nil, icon_emoji: nil, username: nil)
        super(env: env, team: team, channel: channel, token: token, webhook: webhook)
        @icon_url = icon_url
        @icon_emoji = icon_emoji
        @username = username
      end

      def payload_for_updating
        make_message(super.merge(color: '#E7E7E7'))
      end

      def payload_for_reverting
        make_message(super.merge(color: '#E7E7E7'))
      end

      def payload_for_updated
        make_message(super.merge(color: 'good'))
      end

      def payload_for_reverted
        make_message(super.merge(color: 'good'))
      end

      def payload_for_failed
        make_message(super.merge(color: 'danger'))
      end

      def icon_url
        if @icon_url.nil?
          super
        else
          @icon_url
        end
      end

      def icon_emoji
        @icon_emoji
      end

      def username
       if @username.nil?
         super
       else
         @username
       end
      end

      private ##################################################

      def make_message(options={})
        attachment = options.reject{|k, v| v.nil? }
        {attachments: [attachment]}
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capistrano-wearerequired-0.4.0.pre.alpha.2 lib/capistrano/wearerequired/slackistrano_messaging_colors.rb
capistrano-wearerequired-0.4.0.pre.alpha.1 lib/capistrano/wearerequired/slackistrano_messaging_colors.rb