Class: ConsulWatcher::WatchType::Checks

Inherits:
Object
  • Object
show all
Defined in:
lib/consul_watcher/watch_type/checks.rb

Instance Method Summary collapse

Constructor Details

#initialize(destination_config) ⇒ Checks

Returns a new instance of Checks.



8
# File 'lib/consul_watcher/watch_type/checks.rb', line 8

def initialize(destination_config) end

Instance Method Details

#get_changes(previous_watch_json, current_watch_json) ⇒ Object



10
11
12
13
14
# File 'lib/consul_watcher/watch_type/checks.rb', line 10

def get_changes(previous_watch_json, current_watch_json)
  HashDiff.diff(json_to_hash(previous_watch_json),
                json_to_hash(current_watch_json),
                array_path: true)
end

#id(change) ⇒ Object



16
17
18
# File 'lib/consul_watcher/watch_type/checks.rb', line 16

def id(change)
  "key.#{change[1][0].tr('/', '.')}"
end

#json_to_hash(json) ⇒ Object



20
21
22
23
24
25
# File 'lib/consul_watcher/watch_type/checks.rb', line 20

def json_to_hash(json)
  json = '{}' if json.nil? || json == "null\n"
  JSON.parse(json).map do |check|
    { check['Node'] => { check['CheckID'] => check } }
  end.reduce({}, :merge)
end