lib/reap/task.rb in reap-4.3.4 vs lib/reap/task.rb in reap-4.4.0
- old
+ new
@@ -5,11 +5,11 @@
require 'facet/fileutils/safe_ln'
require 'facet/string/tabto'
require 'facet/module/basename'
require 'facet/module/attr_setter'
-require 'facet/filelist'
+require 'facet/filelist' unless defined?( FileList )
require 'facet/openobject'
# _____ _ ___ ___ _
# |_ _|_ _ __| |__ | _ ) __ _ ___ ___ / __| |__ _ ______
# | |/ _` (_-< / / | _ \/ _` (_-</ -_) | (__| / _` (_-<_-<
@@ -47,14 +47,14 @@
module Reap
class Task
- include ::Config
+ #include ::Config
include ::FileUtils
- RUBY = CONFIG['ruby_install_name']
+ RUBY = ::Config::CONFIG['ruby_install_name']
class << self
# When this class is inherited the new task is registered.
@@ -64,20 +64,24 @@
def task_list
@task_list ||= {}
end
+ # task dsl
+
+ def section_required( val ) ; @section_required = val ; end
+ def section_required? ; @section_required ; end
+
def task_name
basename.downcase
end
def task_desc( text=nil, &block )
return @task_desc = proc { text } if text
return @task_desc = block if block_given?
return @task_desc.call
end
- #def task_desc ; '(no desciption given)' ; end
def task_help( text=nil, &block )
return @task_help = proc { text } if text
return @task_help = block if block_given?
return @task_help.call
@@ -85,12 +89,10 @@
def task_attr( name )
define_method(name) { @task }
end
- def section_required( val ) ; @section_required = val ; end
- def section_required? ; @section_required ; end
def verify?
if section_required?
return $PROJECT_INFO.info.key?(task_name)
end
@@ -99,19 +101,10 @@
def master
@master ||= CascadingOpenObject.new( $PROJECT_INFO )
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
-
# properties not to be looked up in master
# if they are not in regular task section
# def task_only_properties ; @task_only_properties ||= [] ; end
# def task_only_property( *names )
@@ -134,55 +127,60 @@
def section ; @section ; end
def task ; @task ; end
def initialize( *args )
#@master = CascadingOpenObject.new( $PROJECT_INFO )
- section = master[task_name]
+ @args = args
+ end
+
+ # Run task for each section entires given.
+
+ def execute( section=nil )
+ section = section || master[task_name]
case section
when Array
section.each do |s|
initiate( s )
end
else
initiate( section )
end
end
- # Per section
+ # Per section entry execution of task.
def initiate( section )
@section = CascadingOpenObject.new( section )
- task_properties = {}
+ task_properties = {} # needed?
#self.class.task_only_properties.each { |t| section[t] ||= nil }
task_properties = CascadingOpenObject.new( section )
task_properties.__parent__ = master
@task = task_properties
- init #task
- run #task
+ # deprecate init ?
+ if respond_to?( :init )
+ if method(:init).arity == 0
+ init
+ else
+ init( *@args )
+ end
+ end
+
+ if method(:run).arity == 0
+ run
+ else
+ run( *@args )
+ end
end
-# def set( sec )
-#
-# #@task = @section #TaskProperties.new( @master, @section )
-#
-# #self.class.master_attributes.each do |k,v|
-# # send( "#{k}=", @master[k] )
-# #end
-#
-# #@section.each do |k,v|
-# # send( "#{k}=", v )
-# #end
-# end
+ # interface
- # the two primary methods
+ #def init
+ # raise "not implemented for '#{task_name}' task"
+ #end
- def init
- raise "not implemented for '#{task_name}' task"
- end
-
def run
raise "no action defined for task #{task_name}"
end
# Task support methods
@@ -198,12 +196,23 @@
def sh( arg )
puts arg
system arg unless $PRETEND
end
+ def ask( question, answers=nil )
+ print "#{question}"
+ print " [#{answers}] " if answers
+ until inp = $stdin.gets[0,1] ; sleep 1 ; end ; puts
+ inp
+ end
+
+ def tell( statement )
+ puts statement
+ end
+
def provide_setup_rb
return true if File.exists?( 'setup.rb')
- # copy from data dir to current directory
+ # copy from data dir to current directory (Won't work with Gem!)
f = File.join( Config::CONFIG['datadir'], 'reap', 'setup_rb', 'setup.rb' )
if File.exists?(f)
File.cp( f, '.' )
true
else