Class: SlackNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/slackbot/slack_notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ SlackNotifier

Returns a new instance of SlackNotifier.



7
8
9
10
11
12
# File 'lib/capistrano/slackbot/slack_notifier.rb', line 7

def initialize(args = {})
  @webhook_url = args.fetch(:webhook_url) {
    raise ArgumentError, "[capistrano-slackbot] webhook_url not set!"
  }
  @options = args.fetch(:options) { {} }
end

Instance Attribute Details

#webhook_urlObject (readonly)

Returns the value of attribute webhook_url.



5
6
7
# File 'lib/capistrano/slackbot/slack_notifier.rb', line 5

def webhook_url
  @webhook_url
end

Instance Method Details

#notify(text) ⇒ Object



14
15
16
17
18
# File 'lib/capistrano/slackbot/slack_notifier.rb', line 14

def notify(text)
  payload = { text: text }.merge(@options)

  connection.post webhook_url, payload.to_json
end