lib/reap/projectinfo.rb in reap-4.0.0 vs lib/reap/projectinfo.rb in reap-4.3.1
- old
+ new
@@ -1,38 +1,72 @@
require 'yaml'
+
require 'facet/hash/traverse'
require 'facet/string/tabto'
+require 'facet/dir/self/ascend'
-module ProjectInfo
- extend self
+class ProjectInfo
INFO_FILES = [ 'ProjectInfo', 'ReapFile', 'projectinfo', 'reapfile' ]
- def add_info_file( f )
+ def self.add_info_file( f )
INFO_FILES.unshift( f )
end
- def info_stream
- unless @info_stream
- info_file = INFO_FILES.find{ |f| File.file?( f ) }
- if info_file
- @info_stream = File.read( info_file )
+ #def self.[](name)
+ # @self ||= self.new
+ # @self[name]
+ #end
+
+ attr_reader :info, :info_stream
+
+ 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 ) }
+ break if info_file
end
end
- @info_stream
- end
-
- def info
- if info_stream
- @info ||= YAML::load(info_stream).traverse{ |k,v| [k.downcase, v] }
+ 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
- {}
+ @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']
@@ -40,6 +74,7 @@
end
def [](name)
info[name]
end
+
end