lib/reap/projectinfo.rb in reap-4.5.2 vs lib/reap/projectinfo.rb in reap-5.0.0

- old
+ new

@@ -7,25 +7,10 @@ require 'facet/kernel/require_all' require 'facet/basicobject' -module Reap - - def self.register #( alternative_project_file=nil ) - pi = ProjectInfo.load( nil, true ) - pi.require_custom_tasks if pi - pi - end - - def self.projectfile? - ProjectInfo.instance.info_file - end - -end - - # Project information, generally read from a file. # Simply by calling 'ProjectInfo.load'. # # ProjectInfo is a Singleton. Access it via the # ProjectInfo.instance method. @@ -47,24 +32,10 @@ def instance( *args, &block ) @instance ||= new( *args, &block ) end - # Load the project information from a file. Generally - # no file needs to be specified; the file will be found - # by ascending up the current path until a default - # file name is found (eg. ProjectInfo or Reapfile). - - def load( fpath=nil, report=false ) - if fpath - new.read( fpath, report ) - else - fpath = find - instance.read( fpath, report ) - end - end - # Find project information file. def find info_dir, info_file = nil, nil Dir.ascend(Dir.pwd) do |info_dir| @@ -73,14 +44,19 @@ end return nil unless info_file return File.join( info_dir, info_file ) end - #def add_file( f ) - # INFO_FILES.unshift( f ) - #end + # Load the project information from a file. Generally + # no file needs to be specified; the file will be found + # by ascending up the current path until a default + # file name is found (eg. ProjectInfo or Reapfile). + def load( fpath=nil ) + instance.read( fpath ) + end + end attr_reader :info, :info_stream, :info_dir, :info_file @@ -109,26 +85,27 @@ self end # Load project information from YAML file. - def read( fpath, report=true ) + def read( fpath ) return unless fpath @info_dir = File.dirname( fpath ) @info_file = fpath #File.basename( fpath ) @info_stream = File.read( fpath ).strip @info = YAML::load( info_stream ).traverse{ |k,v| [k.to_s.downcase, v] } - Dir.chdir(@info_dir) - if report - puts "(in #{Dir.pwd})" #unless dir == Dir.pwd - end - #validate defaults + @info.each do |key, value| + case value when Reap::Task + value.task_name = key + end + end + self end # Update project information. @@ -175,23 +152,10 @@ self['status'] ||= 'Beta' self['project'] ||= self['rubyforge'] ? self['rubyforge']['project'] : nil self['homepage'] ||= self['rubyforge'] ? self['rubyforge']['homepage'] : nil end - # Load custom tasks. - - def require_custom_tasks - # Universal custom tasks for all projects. - dir = File.join( Config::CONFIG['datadir'], 'reap/task' ) - require_all( File.join(dir, '*') ) if File.directory?(dir) - # Personal tasks for all projects. - dir = File.expand_path( '~/.share/reap/task' ) - require_all( File.join(dir, '*') ) if File.directory?(dir) - # Project specific tasks. - require_all('task/*') if File.directory?('task') - end - # Convert to a CascadinOpenObject. def to_cascading_open_object CascadingOpenObject.new( @info ) end @@ -206,13 +170,17 @@ def []=(name, x) info[name] = x end + def each( &block ) + @info.each( &block ) + end + # Information to hash. def to_h - @info + @info.dup end end