Class: EtcdTools::Erb
- Inherits:
-
ERB
- Object
- ERB
- EtcdTools::Erb
show all
- Includes:
- Etcd
- Defined in:
- lib/etcd-tools/erb.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Etcd
#etcd2hash, #etcd_connect, #hash2etcd
Constructor Details
#initialize(etcd, template, requires = ['yaml', 'json']) ⇒ Erb
Returns a new instance of Erb.
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/etcd-tools/erb.rb', line 11
def initialize (etcd, template, requires=['yaml', 'json'])
@safe_level = nil
requires.each do |r|
require r
end
@etcd = etcd
compiler = ::ERB::Compiler.new('-')
set_eoutvar(compiler, "_erbout")
@src, @enc = *compiler.compile(template)
@filename = nil
end
|
Instance Attribute Details
#etcd ⇒ Object
Returns the value of attribute etcd.
9
10
11
|
# File 'lib/etcd-tools/erb.rb', line 9
def etcd
@etcd
end
|
Instance Method Details
#hash(path) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/etcd-tools/erb.rb', line 41
def hash path
begin
etcd2hash @etcd, path
rescue
{}
end
end
|
#keys(path) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/etcd-tools/erb.rb', line 32
def keys path
path.sub!(/^\//, '')
if @etcd.get('/' + path).directory?
return @etcd.get('/' + path).children.map { |key| key.key }
else
return []
end
end
|
#members ⇒ Object
49
50
51
|
# File 'lib/etcd-tools/erb.rb', line 49
def members
Hash[ @etcd.members.map { |id, md| [ id, md.merge({ "ip" => md["clientURLs"].first.sub(/https?:\/\//, '').sub(/:[0-9]+/, '') }) ] } ]
end
|
#result ⇒ Object
24
25
26
|
# File 'lib/etcd-tools/erb.rb', line 24
def result
super binding
end
|
#value(path) ⇒ Object
28
29
30
|
# File 'lib/etcd-tools/erb.rb', line 28
def value path
return @etcd.get('/' + path.sub(/^\//, '')).value
end
|