Class: OpsDeploy::CLI::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ops_deploy/cli/notifier.rb

Overview

Notifier

Defined Under Namespace

Classes: Generic, Messages, Slack

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Notifier



7
8
9
10
11
12
# File 'lib/ops_deploy/cli/notifier.rb', line 7

def initialize(options)
  @options = options
  @options.delete(:slack) if @options[:slack].nil? || @options[:slack][:webhook_url].nil?
  @messages = OpsDeploy::CLI::Notifier::Messages.new
  @notification_type = :info
end

Instance Attribute Details

#messagesObject

Returns the value of attribute messages.



4
5
6
# File 'lib/ops_deploy/cli/notifier.rb', line 4

def messages
  @messages
end

#notification_typeObject

Returns the value of attribute notification_type.



5
6
7
# File 'lib/ops_deploy/cli/notifier.rb', line 5

def notification_type
  @notification_type
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/ops_deploy/cli/notifier.rb', line 3

def options
  @options
end

Instance Method Details

#failure_notify(stack, message) ⇒ Object



41
42
43
44
45
46
# File 'lib/ops_deploy/cli/notifier.rb', line 41

def failure_notify(stack, message)
  return unless @options[:slack]

  OpsDeploy::CLI::Notifier::Slack.new(stack, @options[:slack])
    .failure_notify(message) if @options[:slack]
end

#info_notify(stack, message) ⇒ Object



27
28
29
30
31
32
# File 'lib/ops_deploy/cli/notifier.rb', line 27

def info_notify(stack, message)
  return unless @options[:slack]

  OpsDeploy::CLI::Notifier::Slack.new(stack, @options[:slack])
    .notify(message)
end

#notify(stack) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ops_deploy/cli/notifier.rb', line 14

def notify(stack)
  if @notification_type == :failure
    message = @messages.failure.join("\n")
    failure_notify(stack, message)
  elsif @notification_type == :success
    message = @messages.success.join("\n")
    success_notify(stack, message)
  else
    message = @messages.info.join("\n")
    info_notify(stack, message)
  end
end

#resetObject



48
49
50
51
# File 'lib/ops_deploy/cli/notifier.rb', line 48

def reset
  @messages = OpsDeploy::CLI::Notifier::Messages.new
  @notification_type = :info
end

#success_notify(stack, message) ⇒ Object



34
35
36
37
38
39
# File 'lib/ops_deploy/cli/notifier.rb', line 34

def success_notify(stack, message)
  return unless @options[:slack]

  OpsDeploy::CLI::Notifier::Slack.new(stack, @options[:slack])
    .success_notify(message)
end