Class: Consul::FS::Dir

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDir

Returns a new instance of Dir.



10
11
12
# File 'lib/consul/fs.rb', line 10

def initialize
  @consul = Consul::Client.v1.http
end

Instance Attribute Details

#consulObject (readonly)

Returns the value of attribute consul.



8
9
10
# File 'lib/consul/fs.rb', line 8

def consul
  @consul
end

Instance Method Details

#contents(path) ⇒ Object



14
15
16
17
18
# 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) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# 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) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# 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) ⇒ Object



33
34
35
36
37
# File 'lib/consul/fs.rb', line 33

def read_file(path)
  Base64.decode64(consul.get("/kv#{path}")[0]["Value"])
rescue Consul::Client::ResponseException
  ""
end