Class: Consul::FS::Dir
- Inherits:
-
Object
- Object
- Consul::FS::Dir
- Defined in:
- lib/consul/fs.rb
Instance Attribute Summary collapse
-
#consul ⇒ Object
readonly
Returns the value of attribute consul.
Instance Method Summary collapse
- #contents(path) ⇒ Object
- #directory?(path) ⇒ Boolean
- #file?(path) ⇒ Boolean
-
#initialize ⇒ Dir
constructor
A new instance of Dir.
- #read_file(path) ⇒ Object
Constructor Details
Instance Attribute Details
#consul ⇒ Object (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
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
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 |