class Consul::Async::ConsulTemplateKV
Key/Values representations This is an array as it might contain several values Several helpers exist to handle nicely transformations
Attributes
root[R]
Public Class Methods
new(consul_endpoint, root)
click to toggle source
Calls superclass method
Consul::Async::ConsulTemplateAbstractArray::new
# File lib/consul/async/consul_template.rb, line 680 def initialize(consul_endpoint, root) @root = root super(consul_endpoint) end
Public Instance Methods
find(name = root)
click to toggle source
# File lib/consul/async/consul_template.rb, line 685 def find(name = root) res = result_delegate.find { |k| name == k['Key'] } res || {} end
get_value(name = root)
click to toggle source
Get the raw value (might be base64 encoded)
# File lib/consul/async/consul_template.rb, line 691 def get_value(name = root) find(name)['Value'] end
get_value_decoded(name = root)
click to toggle source
Get the Base64 Decoded value
# File lib/consul/async/consul_template.rb, line 696 def get_value_decoded(name = root) val = get_value(name) return nil unless val Base64.decode64(val) end
get_value_json(name = root, catch_errors: true)
click to toggle source
Helper to get the value decoded as JSON
# File lib/consul/async/consul_template.rb, line 704 def get_value_json(name = root, catch_errors: true) x = get_value_decoded(name) return nil unless x begin JSON.parse(x) rescue JSON::ParserError => e return nil if catch_errors raise StandardError.new(e), "get_value_json() cannot deserialize kv(#{name}) as JSON: #{e.message}", e.backtrace end end
get_value_yaml(name = root, catch_errors: true)
click to toggle source
Helper to get the value decoded as YAML
# File lib/consul/async/consul_template.rb, line 718 def get_value_yaml(name = root, catch_errors: true) x = get_value_decoded(name) return nil unless x begin YAML.safe_load(x) rescue YAML::ParserError => e return nil if catch_errors raise StandardError.new(e), "get_value_yaml() cannot deserialize kv(#{name}) as YAML: #{e.message}", e.backtrace end end