Class: Consul::Async::ConsulTemplateKV
- Inherits:
-
ConsulTemplateAbstractArray
- Object
- ConsulTemplateAbstract
- ConsulTemplateAbstractArray
- Consul::Async::ConsulTemplateKV
- Defined in:
- lib/consul/async/consul_template.rb
Overview
Key/Values representations This is an array as it might contain several values Several helpers exist to handle nicely transformations
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Attributes inherited from ConsulTemplateAbstract
Instance Method Summary collapse
- #find(name = root) ⇒ Object
-
#get_value(name = root) ⇒ Object
Get the raw value (might be base64 encoded).
-
#get_value_decoded(name = root) ⇒ Object
Get the Base64 Decoded value.
-
#get_value_json(name = root, catch_errors: true) ⇒ Object
Helper to get the value decoded as JSON.
-
#get_value_yaml(name = root, catch_errors: true) ⇒ Object
Helper to get the value decoded as YAML.
-
#initialize(consul_endpoint, root) ⇒ ConsulTemplateKV
constructor
A new instance of ConsulTemplateKV.
Methods inherited from ConsulTemplateAbstract
#_seen_at, #method_missing, #ready?, #respond_to_missing?
Constructor Details
#initialize(consul_endpoint, root) ⇒ ConsulTemplateKV
Returns a new instance of ConsulTemplateKV.
687 688 689 690 |
# File 'lib/consul/async/consul_template.rb', line 687 def initialize(consul_endpoint, root) @root = root super(consul_endpoint) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Consul::Async::ConsulTemplateAbstract
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
685 686 687 |
# File 'lib/consul/async/consul_template.rb', line 685 def root @root end |
Instance Method Details
#find(name = root) ⇒ Object
692 693 694 695 |
# File 'lib/consul/async/consul_template.rb', line 692 def find(name = root) res = result_delegate.find { |k| name == k['Key'] } res || {} end |
#get_value(name = root) ⇒ Object
Get the raw value (might be base64 encoded)
698 699 700 |
# File 'lib/consul/async/consul_template.rb', line 698 def get_value(name = root) find(name)['Value'] end |
#get_value_decoded(name = root) ⇒ Object
Get the Base64 Decoded value
703 704 705 706 707 708 |
# File 'lib/consul/async/consul_template.rb', line 703 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) ⇒ Object
Helper to get the value decoded as JSON
711 712 713 714 715 716 717 718 719 720 721 722 |
# File 'lib/consul/async/consul_template.rb', line 711 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.}", e.backtrace end end |
#get_value_yaml(name = root, catch_errors: true) ⇒ Object
Helper to get the value decoded as YAML
725 726 727 728 729 730 731 732 733 734 735 736 |
# File 'lib/consul/async/consul_template.rb', line 725 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.}", e.backtrace end end |