class Consul::Response
Attributes
data[R]
response[R]
Public Class Methods
new(net_http_response, request_path='/')
click to toggle source
# File lib/consul/response.rb, line 16 def initialize(net_http_response, request_path='/') @response = net_http_response @request_path = File.dirname(request_path) end
Public Instance Methods
success?()
click to toggle source
def locked?
to_h.has_key?("Session")
end
# File lib/consul/response.rb, line 33 def success? response.code_type == Net::HTTPOK end
value()
click to toggle source
# File lib/consul/response.rb, line 25 def value @value ||= to_ruby end
Private Instance Methods
build_data_hash(hash_path, consul_metadata)
click to toggle source
# File lib/consul/response.rb, line 48 def build_data_hash(hash_path, consul_metadata) hash_path.split('/').reverse.inject(Data.new(consul_metadata)) { |memo,key| { key => memo } } end
init_data()
click to toggle source
# File lib/consul/response.rb, line 39 def init_data {}.tap do |retval| to_ruby.each do |metadata| hash_path = metadata['Key'].gsub(%r{^/?#{@request_path}/?}, '') retval.merge!(build_data_hash(hash_path,metadata), &merger) end end end
merger()
click to toggle source
# File lib/consul/response.rb, line 62 def merger proc { |key,new,old| new.respond_to?(:merge) && new.class == old.class ? new.merge(old, &merger) : old } end
to_ruby()
click to toggle source
# File lib/consul/response.rb, line 52 def to_ruby if response.code_type == Net::HTTPOK Psych.safe_load(response.body) elsif response.code_type == Net::HTTPNotFound raise KeyError, "Requested key not found" else raise "Request failed" end end