class Consul::FS::Dir

Attributes

consul[R]

Public Class Methods

new() click to toggle source
# File lib/consul/fs.rb, line 10
def initialize
  @consul = Consul::Client.v1.http
end

Public Instance Methods

contents(path) click to toggle source
# File lib/consul/fs.rb, line 14
def contents(path)
  path += "/" unless path.end_with?("/")
  consul.get("/kv#{path}?recurse&separator=/&keys")
    .map {|x| x[path.length-1..-1] }
end
directory?(path) click to toggle source
# File lib/consul/fs.rb, line 27
def directory?(path)
  consul.get("/kv#{path}?keys").any? {|x| x.include?("#{path[1..-1]}/") }
rescue Consul::Client::ResponseException
  false
end
file?(path) click to toggle source
# File lib/consul/fs.rb, line 20
def file?(path)
  consul.get("/kv#{path}?keys")
  true
rescue Consul::Client::ResponseException
  false
end
read_file(path) click to toggle source
# File lib/consul/fs.rb, line 33
def read_file(path)
  Base64.decode64(consul.get("/kv#{path}")[0]["Value"])
rescue Consul::Client::ResponseException
  ""
end