class ConfUtils::Props

Constants

VERSION

Attributes

parent[R]
path[R]

Public Class Methods

load_file( path, parent=nil ) click to toggle source
# File lib/props/props.rb, line 13
def self.load_file( path, parent=nil )
  h = YAML.load_file( path )
  Props.new( h, path, parent )
end
load_file_with_erb( path, binding, parent=nil ) click to toggle source

todo: use TOP_LEVEL_BINDING for binding default?

# File lib/props/props.rb, line 19
def self.load_file_with_erb( path, binding, parent=nil )  # run through erb first
  text = ERB.new( File.read( path ) ).result( binding )
  h = YAML.load( text )
  Props.new( h, path, parent )
end
new( hash, path, parent=nil) click to toggle source
# File lib/props/props.rb, line 26
def initialize( hash, path, parent=nil)
  @hash   = hash
  @path   = path
  @parent = parent
end

Public Instance Methods

[](key) click to toggle source
# File lib/props/props.rb, line 48
def [](key)  get( key );  end
dump() click to toggle source
# File lib/props/props.rb, line 32
def dump   # for debugging
  puts "dump of >#{@path}<:"
  pp @hash
end
fetch(key, default) click to toggle source
# File lib/props/props.rb, line 38
def fetch(key, default)
  value = get( key )
  value.nil? ? default : value
end
fetch_from_section(section, key, default) click to toggle source
# File lib/props/props.rb, line 43
def fetch_from_section(section, key, default)
  value = get_from_section( section, key )
  value.nil? ? default : value
end
get( key ) click to toggle source
# File lib/props/props.rb, line 50
def get( key )
  value = @hash.fetch( key.to_s, nil )
  # if not found try lookup in parent hash
  (value.nil? && parent) ? parent.get(key) : value
end
get_from_section( section, key ) click to toggle source
# File lib/props/props.rb, line 56
def get_from_section( section, key )
  value = @hash.fetch( section.to_s, {} ).fetch( key.to_s, nil )
  # if not found try lookup in parent hash
  (value.nil? && parent) ? parent.get_from_section(section,key) : value
end