Class: EtcdTools::Erb
Instance Attribute Summary collapse
-
#etcd ⇒ Object
readonly
Returns the value of attribute etcd.
Instance Method Summary collapse
- #hash(path) ⇒ Object
-
#initialize(etcd, template, requires = ['yaml', 'json', 'time']) ⇒ Erb
constructor
A new instance of Erb.
- #keys(path) ⇒ Object
- #members ⇒ Object
- #result ⇒ Object
- #value(path) ⇒ Object
Methods included from Etcd
Constructor Details
#initialize(etcd, template, requires = ['yaml', 'json', 'time']) ⇒ Erb
Returns a new instance of Erb.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/etcd-tools/erb.rb', line 11 def initialize (etcd, template, requires=['yaml', 'json', 'time']) @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 (readonly)
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
40 41 42 43 44 |
# File 'lib/etcd-tools/erb.rb', line 40 def hash path @etcd.get_hash path rescue {} end |
#keys(path) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/etcd-tools/erb.rb', line 31 def keys path path.sub!(%r{^/+}, '') if @etcd.get('/' + path).directory? return @etcd.get('/' + path).children.map(&:key) else return [] end end |
#members ⇒ Object
46 47 48 |
# File 'lib/etcd-tools/erb.rb', line 46 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 @etcd.get('/' + path.sub(%r{^/+}, '')).value end |