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']) ⇒ Erb
Returns a new instance of Erb.
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/etcd-tools/erb.rb', line 10
def initialize (etcd, template, requires=['yaml'])
@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.
8
9
10
|
# File 'lib/etcd-tools/erb.rb', line 8
def etcd
@etcd
end
|
Instance Method Details
#keys(path) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/etcd-tools/erb.rb', line 31
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
40
41
42
|
# File 'lib/etcd-tools/erb.rb', line 40
def members
Hash[ @etcd.members.map { |id, md| [ id, md.merge({ "ip" => md["clientURLs"].first.sub(/https?:\/\//, '').sub(/:[0-9]+/, '') }) ] } ]
end
|
#result ⇒ Object
23
24
25
|
# File 'lib/etcd-tools/erb.rb', line 23
def result
super binding
end
|
#value(path) ⇒ Object
27
28
29
|
# File 'lib/etcd-tools/erb.rb', line 27
def value path
return @etcd.get('/' + path.sub(/^\//, '')).value
end
|