Class: SensuGenerator::ConsulState

Inherits:
Consul
  • Object
show all
Defined in:
lib/sensu_generator/consul/consul_state.rb

Instance Method Summary collapse

Methods inherited from Consul

#get_service_props, #kv_svc_props, #sensu_servers, #services

Constructor Details

#initializeConsulState

Returns a new instance of ConsulState.



3
4
5
6
7
# File 'lib/sensu_generator/consul/consul_state.rb', line 3

def initialize
  @actual_state = []
  super()
  actualize
end

Instance Method Details

#actualizeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sensu_generator/consul/consul_state.rb', line 13

def actualize
  reset
  @svc_list_diff = services.map {|name, _| name.to_s } - @actual_state.map { |svc| svc.name.to_s}
  @actual_state.each(&:update)
  @svc_list_diff.each do |name|
    @actual_state << ConsulService.new(name: name)
  end
  @actualized = true
  logger.debug "Services actualized list: #{@actual_state.map { |svc| svc.name.to_s} }"
  self
end

#actualized?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sensu_generator/consul/consul_state.rb', line 41

def actualized?
  @actualized ? true : false # For the case when nil
end

#changed?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/sensu_generator/consul/consul_state.rb', line 25

def changed?
  state = !(@svc_list_diff || []).empty? || !changes.empty?
  logger.debug "Consul state was changed: #{state.to_s}"
  state
end

#changesObject



31
32
33
# File 'lib/sensu_generator/consul/consul_state.rb', line 31

def changes
  @svc_changes ||= @actual_state.select(&:changed?)
end

#resetObject



35
36
37
38
39
# File 'lib/sensu_generator/consul/consul_state.rb', line 35

def reset
  @actualized = false
  @svc_changes = nil
  @svc_list_diff = nil
end

#showObject



9
10
11
# File 'lib/sensu_generator/consul/consul_state.rb', line 9

def show
  @actual_state
end