Module: Deploy::Output

Included in:
Runner
Defined in:
lib/deploy/output.rb

Instance Method Summary collapse

Instance Method Details

#announce(attachments) ⇒ Object



4
5
6
7
# File 'lib/deploy/output.rb', line 4

def announce(attachments)
  shout("#{attachments[:title]} - #{attachments[:text]}")
  notifier('', attachments)
end

#colorize(color_code, message) ⇒ Object



47
48
49
# File 'lib/deploy/output.rb', line 47

def colorize(color_code, message)
  "\e[#{color_code}m#{message}\e[0m"
end

#green(message) ⇒ Object



35
36
37
# File 'lib/deploy/output.rb', line 35

def green(message)
  colorize(32, message)
end

#notifier(message, attachments) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/deploy/output.rb', line 9

def notifier(message, attachments)
  if ENV['SLACK_WEBHOOK']
    @notifier ||= Slack::Notifier.new(ENV['SLACK_WEBHOOK'])
    @notifier.ping(message, {
      attachments: [attachments]
    })
  else
    shout 'You can send deployment notifications if you set the SLACK_WEBHOOK environment variable.'
  end
end

#pink(message) ⇒ Object



43
44
45
# File 'lib/deploy/output.rb', line 43

def pink(message)
  colorize(35, message)
end

#red(message) ⇒ Object



31
32
33
# File 'lib/deploy/output.rb', line 31

def red(message)
  colorize(31, message)
end

#shout(message) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/deploy/output.rb', line 20

def shout(message)
  message_size = message.size
  if message_size < 77
    # lines are always 80 characters
    stars = '*' * (77 - message_size)
    puts(red("+ ") + "#{message} #{red(stars)}")
  else
    puts(red('+ ') + message)
  end
end

#yellow(message) ⇒ Object



39
40
41
# File 'lib/deploy/output.rb', line 39

def yellow(message)
  colorize(33, message)
end