Sha256: 4270d0f11d748f4ce84e60c7f4cdeed9432ecd2612b4de18f34f8a8e7868ad2f

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

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

  def to_h
    @info
  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reap-4.3.3 lib/reap/projectinfo.rb