Sha256: f9d4e789cd61fb12c41aa96a223601cfc73a0b54ce28339f36260ba82f181b64

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reap-4.0 lib/reap/projectinfo.rb
reap-5.10.10 lib/reap/projectinfo.rb