class Fuzz::OPTIONS::Config
Public Class Methods
new(hash=nil)
click to toggle source
Calls superclass method
# File lib/fuzz/options.rb, line 33 def initialize(hash=nil) super @table = _merge(_defaults, @table) end
Public Instance Methods
load(rcpath)
click to toggle source
# File lib/fuzz/options.rb, line 47 def load(rcpath) log(3, "Loading #{FUZZRC} from #{rcpath}") _cfg = YAML.load(IO.read(rcpath)) log(4, "Read from #{rcpath}: [#{_cfg}]") # handle automatic env var expansion in fzzr_paths _cfg[:fzzr_paths] = (_cfg[:fzzr_paths] || []).collect do |p| log(5, "Examining fzzr_path [#{p}]") # for paths coming from rc files environment vars are immediately expanded and p.gsub!(/\$([^\s\/]+)/) { |m| ENV[$1] } log(6, "Expanded fzzr_path [#{p}]") # resulting relative paths converted to absolute paths if File.directory?(p) # relative to working dir? p = File.expand_path(p) else # relative to rc location? _fp = File.expand_path(File.join(File.dirname(rcpath), p)) log(4, "Ignoring invalid fuzzer search path #{p} configured in #{rcpath}") unless File.directory?(_fp) p = _fp end log(4, "Adding fuzzer search path: #{p}") p end merge(_cfg) end
merge(from)
click to toggle source
# File lib/fuzz/options.rb, line 42 def merge(from) _merge(@table, from) self end
options()
click to toggle source
# File lib/fuzz/options.rb, line 38 def options Fuzz.options end
save(rcpath)
click to toggle source
# File lib/fuzz/options.rb, line 71 def save(rcpath) File.open(rcpath, 'w') {|f| f << YAML.dump(@table) } end
Protected Instance Methods
_defaults()
click to toggle source
# File lib/fuzz/options.rb, line 77 def _defaults { :brix_paths => [] } end
_merge(to, from)
click to toggle source
# File lib/fuzz/options.rb, line 83 def _merge(to, from) from.each_pair do |(k,v)| k = k.to_sym if to.has_key?(k) case to[k] when Array to[k].concat v when Hash to[k].merge!(v) when OpenStruct _merge(to[k].__send__(:table), v) else to[k] = v end else to[k] = v end end to end