lib/reap/task.rb in reap-4.0.0 vs lib/reap/task.rb in reap-4.3.1
- old
+ new
@@ -1,19 +1,16 @@
-#require 'rake'
-#require 'rake/tasklib'
-
require 'rbconfig'
require 'fileutils'
require 'facet/fileutils/safe_ln'
require 'facet/string/tabto'
require 'facet/module/basename'
+require 'facet/module/attr_setter'
-require 'carat/filelist'
+require 'calibre/filelist'
-require 'reap/projectinfo'
# Base class for reap tasks.
#
# Here's an oh so simple example:
#
@@ -42,149 +39,174 @@
# TASK: mytask
# message: Message text, if any.
#
module Reap
+ @registry ||= {}
+
+ # Hash of all task classes
def self.registry ; @registry ; end
- def self.register( name, klass )
- @registry ||= {}
- if klass.verify
- @registry[name.to_s.downcase] = klass
+ # Hash of tasks available to this project
+ def self.tasks
+ unless @tasks
+ @tasks = {}
+ @registry.each { |name, klass|
+ @tasks[name] = klass if klass.verify?
+ }
end
+ @tasks
end
- def self.tasks ; @tasks ; end
-
- def self.initialize_all
- @tasks ||= {}
- registry.each do |name, klass|
- @tasks[name] = klass.new
- end
+ def self.register
+ $PROJECT_INFO = ProjectInfo.new( $PROJECT_FILE )
+ #@registry ||= {}
+ #ObjectSpace.each_object(Class) { |klass|
+ # if klass < ::Reap::Task
+ # if klass.verify
+ # @registry[klass.basename.downcase] = klass
+ # end
+ # end
+ #}
end
+# def self.initialize
+# @tasks ||= {}
+# registry.each do |name, klass|
+# @tasks[name] = klass.new
+# end
+# end
- class Task #< ::Rake::TaskLib
+
+ class Task
+
include ::Config
include ::FileUtils
RUBY = CONFIG['ruby_install_name']
- # class methods
+ class << self
- def self.inherited( task_class )
- Reap::register( task_class.task_name, task_class )
- end
+ def task_desc( text=nil, &block )
+ if text
+ @task_desc = proc { text }
+ elsif block_given?
+ @task_desc = block
+ else
+ @task_desc.call
+ end
+ end
- def self.task_desc ; '(no desciption given)' ; end
- def self.task_name ; basename.downcase ; end
+ #def task_desc ; '(no desciption given)' ; end
+ def task_name ; basename.downcase ; end
- def self.section_required( val ) ; @section_required = val ;end
- def self.section_required? ; @section_required ; end
+ def section_required( val ) ; @section_required = val ;end
+ def section_required? ; @section_required ; end
- def self.verify
- assume = true
- if section_required?
- assume = ::ProjectInfo.info.key?(task_name)
+ #
+ def verify?
+ if section_required?
+ return $PROJECT_INFO.info.key?(task_name)
+ end
+ true
end
- assume
+
+ def inherited( base )
+ Reap.registry[base.task_name] = base
+ end
+
+ def master_attributes ; @master_attributes ||= [] ; end
+
+ # Use this DSL method to define master task attributes.
+ def attr_master( *names )
+ attr_accessor *names
+ @master_attributes ||= []
+ @master_attributes |= names.collect { |n| n.to_s }
+ end
+
end
# instance methods
def task_name ; self.class.task_name ; end
def task_desc ; self.class.task_desc ; end
- def master ; ::ProjectInfo.info ; end
+ def section_required? ; self.class.section_required? ; end
+ #def master ; ::ProjectInfo.info ; end
+ def master ; @master ; end
def section ; @section ; end
- def section_required? ; self.class.section_required? ; end
+ #
+ def initialize( *args )
+ @master = $PROJECT_INFO
- def initialize
- sect = master[task_name]
+ sect = @master[task_name]
if sect.is_a?(Array)
- sect.each do |s|
- section_parameters_set( s )
+ @master[task_name].each do |sec|
+ set( sec )
init
+ run
end
else
- section_parameters_set( sect || {} )
+ set( sect || {} )
init
+ run
end
end
- def section_parameters_set( s )
- @section = s
- @section.each { |k,v| send("#{k}=", v) }
+ def set( sec )
+ @section = sec
+
+ self.class.master_attributes.each do |k,v|
+ send( "#{k}=", @master[k] )
+ end
+
+ @section.each do |k,v|
+ send( "#{k}=", v )
+ end
end
def init
raise "not implemented for '#{task_name}' task"
end
- def run( *args )
+ def run
raise "no action defined for task #{task_name}"
end
# task support methods
def sh( arg )
puts arg
system arg unless $PRETEND
end
-# o = nil
-# o = yld.call(self) if yld
-# if String === o
-# begin
-# section( o ).each { |k,v| send("#{k}=", v ) }
-# end
-# end
-#
-# init
-#
-# task_name ||= default_name
-# task_desc = @desc || default_desc
-#
-# if subtask
-# desc task_desc
-# task task_name => subtask do
-# run
-# end
-# else
-# desc task_desc
-# task task_name do
-# run
-# end
-# end
-# end
-
end #class Task
end #module Reap
##
# Convenience methods for built-in rake tasks
##
# module RakeTask
# extend self
-#
+#
# def gem_package_task(*args,&blk)
# ::Rake::GemPackageTask.new(*args,&blk)
# end
-#
+#
# def package_task(*args,&blk)
# ::Rake::PackageTask.new(*args,&blk)
# end
-#
+#
# def test_task(*args,&blk)
# ::Rake::TestTask.new(*args,&blk)
# end
-#
+#
# def rdoc_task(*args,&blk)
# ::Rake::RDocTask.new(*args,&blk)
# end
-#
+#
# end