Class: Consul::Async::ConsulTemplateServices

Inherits:
ConsulTemplateAbstractMap show all
Defined in:
lib/consul/async/consul_template.rb

Overview

Object returned by services() an abstract map of service_name, tags

Instance Attribute Summary

Attributes inherited from ConsulTemplateAbstract

#endpoint, #result, #seen_at

Instance Method Summary collapse

Methods inherited from ConsulTemplateAbstract

#_seen_at, #method_missing, #ready?, #respond_to_missing?

Constructor Details

#initialize(consul_endpoint) ⇒ ConsulTemplateServices

Returns a new instance of ConsulTemplateServices.



588
589
590
# File 'lib/consul/async/consul_template.rb', line 588

def initialize(consul_endpoint)
  super(consul_endpoint)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Consul::Async::ConsulTemplateAbstract

Instance Method Details

#parse_result(res) ⇒ Object



592
593
594
595
596
597
598
599
600
601
602
# File 'lib/consul/async/consul_template.rb', line 592

def parse_result(res)
  return res unless res.data == '{}' || endpoint.query_params[:tag]

  res_json = JSON.parse(res.data)
  result = {}
  res_json.each do |name, tags|
    result[name] = tags if tags.include? endpoint.query_params[:tag]
  end
  res.mutate(JSON.generate(result))
  res
end