Class: Slackistrano::Capistrano

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/slackistrano/capistrano.rb

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Capistrano

Returns a new instance of Capistrano.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/slackistrano/capistrano.rb', line 17

def initialize(env)
  @env = env
  config = fetch(:slackistrano, {})
  @messaging = case config
               when false
                 Messaging::Null.new
               when -> (o) { o.empty? }
                 klass = Messaging::Deprecated.new(
                   env: @env,
                   team: fetch(:slack_team),
                   channel: fetch(:slack_channel),
                   token: fetch(:slack_token),
                   webhook: fetch(:slack_webhook)
                 )
               else
                 opts = config.dup.merge(env: @env)
                 klass = opts.delete(:klass) || Messaging::Default
                 klass.new(opts)
               end
end

Instance Method Details

#process(action, backend) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/slackistrano/capistrano.rb', line 43

def process(action, backend)
  @backend = backend

  payload = @messaging.payload_for(action)
  return if payload.nil?

  payload = {
    username: @messaging.username,
    icon_url: @messaging.icon_url,
    icon_emoji: @messaging.icon_emoji,
  }.merge(payload)

  channels = Array(@messaging.channels_for(action))
  if !@messaging.via_slackbot? == false && channels.empty?
    channels = [nil] # default webhook channel
  end

  channels.each do |channel|
    post(payload.merge(channel: channel))
  end
end

#run(action) ⇒ Object



38
39
40
41
# File 'lib/slackistrano/capistrano.rb', line 38

def run(action)
  _self = self
  run_locally { _self.process(action, self) }
end