Class: ConsulStockpile::LoadJsonKV

Inherits:
Base
  • Object
show all
Defined in:
lib/consul_stockpile/load_json_kv.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call

Constructor Details

#initialize(json:) ⇒ LoadJsonKV

Returns a new instance of LoadJsonKV.



8
9
10
# File 'lib/consul_stockpile/load_json_kv.rb', line 8

def initialize(json:)
  self.json = json
end

Instance Attribute Details

#jsonObject

Returns the value of attribute json.



6
7
8
# File 'lib/consul_stockpile/load_json_kv.rb', line 6

def json
  @json
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/consul_stockpile/load_json_kv.rb', line 12

def call
  Logger.info 'Loading json backup into consul kv store'

  return if json.nil?
  ary = JSON.parse(json)
  return if ary.empty?

  ary.each do |item|
    Diplomat::Kv.put(item['key'], item['value'])
  end
end