Class: Slack::Cap::SlackNotifierWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/slack-cap/slack_notifier_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ SlackNotifierWrapper

Returns a new instance of SlackNotifierWrapper.



6
7
8
9
10
11
12
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 6

def initialize(opts)
  @app      = opts.fetch(:app)
  @team     = opts.fetch(:team)
  @token    = opts.fetch(:token)
  @channel  = opts.fetch(:channel)
  @username = opts[:username] ||'capistrano'
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



4
5
6
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 4

def app
  @app
end

#channelObject

Returns the value of attribute channel.



4
5
6
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 4

def channel
  @channel
end

#teamObject

Returns the value of attribute team.



4
5
6
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 4

def team
  @team
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 4

def token
  @token
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 4

def username
  @username
end

Instance Method Details

#deployerObject



14
15
16
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 14

def deployer
  ENV['GIT_AUTHOR_NAME'] || `git config user.name`.chomp
end

#notifierObject



31
32
33
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 31

def notifier
  @notifier ||= ::Slack::Notifier.new(team, token, channel: channel, username: username)
end

#notify(msg, icon_emoji: ':rocket:') ⇒ Object



23
24
25
26
27
28
29
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 23

def notify(msg, icon_emoji: ':rocket:')
  begin
    notifier.ping(msg, icon_emoji: icon_emoji)
  rescue Net::OpenTimeout, Net::ReadTimeout
    puts Colorize.red("SLACK TIMEOUT")
  end
end

#reasonObject



18
19
20
21
# File 'lib/slack-cap/slack_notifier_wrapper.rb', line 18

def reason
  raise "provice a reason with MSG=... !" unless ENV['MSG']
  ENV['MSG']
end