Class: SensuGenerator::ConsulService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Consul

#get_service_props, #kv_svc_props, #sensu_servers, #services

Constructor Details

#initialize(name:) ⇒ ConsulService

Returns a new instance of ConsulService.



6
7
8
9
10
11
12
# File 'lib/sensu_generator/consul/consul_service.rb', line 6

def initialize(name:)
  @name    = name
  @changed = true
  super()
  all_properties
  self
end

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks.



4
5
6
# File 'lib/sensu_generator/consul/consul_service.rb', line 4

def checks
  @checks
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/sensu_generator/consul/consul_service.rb', line 4

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



4
5
6
# File 'lib/sensu_generator/consul/consul_service.rb', line 4

def properties
  @properties
end

Instance Method Details

#all_propertiesObject Also known as: get_all_properties



14
15
16
17
# File 'lib/sensu_generator/consul/consul_service.rb', line 14

def all_properties
  properties = get_props.class == Array ? get_props.map {|el| el.to_h} : get_props.to_h
  @all_properties ||= { checks: get_checks, properties: properties }
end

#changed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sensu_generator/consul/consul_service.rb', line 36

def changed?
  @changed
end

#get_checksObject



21
22
23
# File 'lib/sensu_generator/consul/consul_service.rb', line 21

def get_checks
  @checks ||= kv_svc_props(key: config.get[:kv_tags_path])
end

#get_propsObject



25
26
27
# File 'lib/sensu_generator/consul/consul_service.rb', line 25

def get_props
  @properties ||= get_service_props(name)
end

#resetObject



40
41
42
43
44
45
# File 'lib/sensu_generator/consul/consul_service.rb', line 40

def reset
  @all_properties = nil
  @properties     = nil
  @checks         = nil
  @changed = false
end

#updateObject



29
30
31
32
33
34
# File 'lib/sensu_generator/consul/consul_service.rb', line 29

def update
  old_all_properties = all_properties.clone
  reset
  get_all_properties
  @changed = true if all_properties != old_all_properties
end