Class: Lbrt::Alert::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/lbrt/alert/exporter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ Exporter

of class methods



8
9
10
11
# File 'lib/lbrt/alert/exporter.rb', line 8

def initialize(client, options = {})
  @client = client
  @options = options
end

Class Method Details

.export(client, options = {}) ⇒ Object



3
4
5
# File 'lib/lbrt/alert/exporter.rb', line 3

def export(client, options = {})
  self.new(client, options).export
end

Instance Method Details

#exportObject



13
14
15
16
# File 'lib/lbrt/alert/exporter.rb', line 13

def export
  alerts = @client.alerts.get
  normalize(alerts)
end

#normalize(alerts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lbrt/alert/exporter.rb', line 18

def normalize(alerts)
  alert_by_name = {}

  alerts.each do |alrt|
    name = alrt.delete('name')

    if alert_by_name[name]
      raise "Duplicate alert name exists: #{name}"
    end

    %w(created_at updated_at version).each do |key|
      alrt.delete(key)
    end

    alrt['attributes'] ||= {}
    alert_by_name[name] = alrt
  end

  alert_by_name
end