Class: Consul::Async::RemoteResource

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

Overview

Class to handle the retrival of a Remote resource (such a JSON API)

Instance Method Summary collapse

Constructor Details

#initialize(endpoints_manager) ⇒ RemoteResource

Returns a new instance of RemoteResource.



28
29
30
# File 'lib/consul/async/consul_template.rb', line 28

def initialize(endpoints_manager)
  @endp_manager = endpoints_manager
end

Instance Method Details

#as_json(url, default_value, refresh_delay_secs: 10, default_value_on_error: false, **opts) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/consul/async/consul_template.rb', line 32

def as_json(url, default_value, refresh_delay_secs: 10, default_value_on_error: false, **opts)
  conf = JSONConfiguration.new(url: url, min_duration: refresh_delay_secs, retry_on_non_diff: refresh_delay_secs, **opts)
  endpoint_id = url + opts.hash.to_s
  @endp_manager.create_if_missing(url, {}, endpoint_id: endpoint_id) do
    if default_value.is_a?(Array)
      ConsulTemplateJSONArray.new(JSONEndpoint.new(conf, url, default_value, default_value_on_error: default_value_on_error))
    else
      ConsulTemplateJSONObject.new(JSONEndpoint.new(conf, url, default_value, default_value_on_error: default_value_on_error))
    end
  end
end