Class: Consul::Client::OfflineConnection

Inherits:
Connection
  • Object
show all
Defined in:
lib/consul/client/offline_connection.rb

Instance Method Summary collapse

Methods inherited from Connection

#config, #decode, #decode_r, #encode, #encode_r, #http, #path, #read, #read_value_r

Instance Method Details

#delete(keypath, opts = {}) ⇒ Object



18
19
20
21
# File 'lib/consul/client/offline_connection.rb', line 18

def delete(keypath, opts={})
  #do nothing, lets not delete our local files
  true
end

#read_obj(keypath, opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/consul/client/offline_connection.rb', line 7

def read_obj(keypath, opts={})
  keyname = File.basename(keypath)

  response = http_get(keypath, opts)
  if response.length == 1 && response.keys.first == keyname
    response[keyname]
  else
    response
  end
end

#write(keypath, data = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/consul/client/offline_connection.rb', line 23

def write(keypath,data=nil)
  data = encode(data)
  filename = File.join(local_path, path(keypath) + ".yaml")
  dirname = File.dirname(filename)

  unless File.directory?(dirname)
    FileUtils.mkdir_p(dirname)
  end
  File.open(filename, 'w') { |f| f.write(data) }
  Consul::Response.new(Consul::Client::FakeNetHttpResponse.new)
end