Sha256: 817bd28703e9133062ed639d23b0d34a0c682c3ca1862bd286a2fcb4623fbe47

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'forwardable'
require_relative 'helpers'

module Slackistrano
  module Messaging
    class Base

      include Helpers

      extend Forwardable
      def_delegators :env, :fetch

      attr_reader :team, :token, :webhook

      def initialize(env: nil, team: nil, channel: nil, token: nil, webhook: nil)
        @env = env
        @team = team
        @channel = channel
        @token = token
        @webhook = webhook
      end

      def payload_for_updating
        {
          text: "#{deployer} has started deploying branch #{branch} of #{application} to #{stage}"
        }
      end

      def payload_for_reverting
        {
          text: "#{deployer} has started rolling back branch #{branch} of #{application} to #{stage}"
        }
      end

      def payload_for_updated
        {
          text: "#{deployer} has finished deploying branch #{branch} of #{application} to #{stage}"
        }
      end

      def payload_for_reverted
        {
          text: "#{deployer} has finished rolling back branch of #{application} to #{stage}"
        }
      end

      def payload_for_failed
        {
          text: "#{deployer} has failed to #{deploying? ? 'deploy' : 'rollback'} branch #{branch} of #{application} to #{stage}"
        }
      end

      def channels_for(action)
        @channel
      end

      ################################################################################

      def payload_for(action)
        method = "payload_for_#{action}"
        respond_to?(method) && send(method)
      end

      def via_slackbot?
        @webhook.nil?
      end

    end
  end
end

require_relative 'default'
require_relative 'deprecated'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slackistrano-3.1.0 lib/slackistrano/messaging/base.rb
slackistrano-3.1.0.beta lib/slackistrano/messaging/base.rb