Class: Martilla::Notifier

Inherits:
Component show all
Defined in:
lib/martilla/notifier.rb

Direct Known Subclasses

EmailNotifier, Slack

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#bash

Constructor Details

#initialize(config) ⇒ Notifier

Returns a new instance of Notifier.

Raises:



5
6
7
8
# File 'lib/martilla/notifier.rb', line 5

def initialize(config)
  @options = config
  raise Error.new(invalid_options_msg) if @options.nil?
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.create(config = {}) ⇒ Object

When a new Notifier is supported it needs to go here



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/martilla/notifier.rb', line 35

def self.create(config = {})
  case config['type'].downcase
  when 'sendmail'
    Sendmail.new(config['options'])
  when 'smtp'
    Smtp.new(config['options'])
  when 'ses'
    Ses.new(config['options'])
  when 'slack'
    Slack.new(config['options'])
  when 'none'
    nil
  else
    raise Error.new("Invalid Notifier type: #{config['type']}")
  end
end

Instance Method Details

#error(msg, data) ⇒ Object

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/martilla/notifier.rb', line 14

def error(msg, data)
  raise NotImplementedError, 'You must implement the error method'
end

#invalid_options_msgObject



18
19
20
# File 'lib/martilla/notifier.rb', line 18

def invalid_options_msg
  'Notifier configuration is invalid. Details here: https://github.com/fdoxyz/martilla'
end

#send_failure?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/martilla/notifier.rb', line 28

def send_failure?
  value = @options['send_failure']
  return true if value.nil?
  value
end

#send_success?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/martilla/notifier.rb', line 22

def send_success?
  value = @options['send_success']
  return true if value.nil?
  value
end

#success(data) ⇒ Object

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/martilla/notifier.rb', line 10

def success(data)
  raise NotImplementedError, 'You must implement the success method'
end