require 'yaml' require 'facet/hash/traverse' require 'facet/string/tabto' require 'facet/dir/self/ascend' class ProjectInfo INFO_FILES = [ 'ProjectInfo', 'ReapFile', 'projectinfo', 'reapfile' ] def self.add_info_file( f ) INFO_FILES.unshift( f ) end #def self.[](name) # @self ||= self.new # @self[name] #end attr_reader :info, :info_stream, :info_dir def initialize( info_file=nil ) unless info_file Dir.ascend(Dir.pwd) do |d| Dir.chdir(d) info_file = INFO_FILES.find{ |f| File.file?( f ) } if info_file @info_dir = d; break end end end if info_file @info_stream = File.read( info_file ) @info = YAML::load( @info_stream ).traverse{ |k,v| [k.downcase, v] } puts "(in #{Dir.pwd})" #unless dir == Dir.pwd else puts "Aborted. No project information file found." exit 1 #@info_stream = "" #@info = {} #puts "(without a project information file)" end 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 # @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