Class: Navy::Etcd

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/etcd.rb

Defined Under Namespace

Classes: Node, Response

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Etcd

Returns a new instance of Etcd.



35
36
37
# File 'lib/navy/etcd.rb', line 35

def initialize(options)
  @options = options
end

Class Method Details

.client(options) ⇒ Object



31
32
33
# File 'lib/navy/etcd.rb', line 31

def self.client(options)
  new(options)
end

Instance Method Details

#delete(key, params = {}) ⇒ Object



77
78
79
80
# File 'lib/navy/etcd.rb', line 77

def delete(key, params = {})
  response = make_delete(key, params)
  (200...299).include? response.code.to_i
end

#get(key, params = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/navy/etcd.rb', line 39

def get(key, params = {})
  response = make_get(key, params)
  json = JSON.parse(response.body)
  Response.new response['X-Etcd-Index'].to_i,
               json['action'],
               Node.new(json['node']),
               Node.new(json['prevNode'])
end

#getJSON(key, params = {}) ⇒ Object



48
49
50
51
52
# File 'lib/navy/etcd.rb', line 48

def getJSON(key, params = {})
  record = get(key, params)
  json = record.node.value
  JSON.parse(json) if json
end

#ls(dir) ⇒ Object



71
72
73
74
75
# File 'lib/navy/etcd.rb', line 71

def ls(dir)
  response = make_get(dir)
  dir = JSON.parse(response.body)["node"]
  dir["nodes"].map {|i| i["key"]}
end

#queueJSON(key, value) ⇒ Object



67
68
69
# File 'lib/navy/etcd.rb', line 67

def queueJSON(key, value)
  make_post(key, :value => value.to_json)
end

#set(key, value) ⇒ Object



59
60
61
# File 'lib/navy/etcd.rb', line 59

def set(key, value)
  make_put(key, :value => value)
end

#setJSON(key, value) ⇒ Object



63
64
65
# File 'lib/navy/etcd.rb', line 63

def setJSON(key, value)
  make_put(key, :value => value.to_json)
end

#watch(key, options = {}) ⇒ Object



54
55
56
57
# File 'lib/navy/etcd.rb', line 54

def watch(key, options = {})
  options[:wait] = true
  get(key, options)
end