class EtcdTools::Erb

Attributes

etcd[R]

Public Class Methods

new(etcd, template, requires=['yaml', 'json', 'time']) click to toggle source
# 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

Public Instance Methods

hash(path) click to toggle source
# File lib/etcd-tools/erb.rb, line 40
def hash path
  @etcd.get_hash path
rescue
  {}
end
keys(path) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
Calls superclass method
# File lib/etcd-tools/erb.rb, line 23
def result
  super binding
end
value(path) click to toggle source
# File lib/etcd-tools/erb.rb, line 27
def value path
  @etcd.get('/' + path.sub(%r{^/+}, '')).value
end