require 'yaml' require 'facet/hash/traverse' require 'facet/string/tabto' require 'facet/dir/self/ascend' module ProjectInfo extend self INFO_FILES = [ 'ProjectInfo', 'ReapFile', 'projectinfo', 'reapfile' ] def add_info_file( f ) INFO_FILES.unshift( f ) end def info_stream dir = Dir.pwd unless @info_stream Dir.ascend(Dir.pwd) do |d| Dir.chdir(d) info_file = INFO_FILES.find{ |f| File.file?( f ) } if info_file @info_stream = File.read( info_file ) puts "(in #{d})" unless dir == Dir.pwd break end end end @info_stream end def info if info_stream @info ||= YAML::load(info_stream).traverse{ |k,v| [k.downcase, v] } else {} end end # not using at the moment def validate # required main parameters #raise "TITLE is a required configuration field" unless info['title'] raise "NAME is a required piece of information" unless info['name'] raise "VERSION is a required piece of informatiomn" unless info['version'] end def [](name) info[name] end end