lib/reap/task.rb in reap-4.3.3 vs lib/reap/task.rb in reap-4.3.4

- old
+ new

@@ -16,92 +16,62 @@ # |_|\__,_/__/_\_\ |___/\__,_/__/\___| \___|_\__,_/__/__/ # # Base class for reap tasks. # -# Here's an oh so simple example: +# Here's a simple example: # # class MyTask < Reap::Task # -# register 'mytask' +# task_desc 'this is a custom reap task' # -# default_desc 'this is a custom reap task' +# task_attr :mytask # -# attr_accessor :message -# # def init -# @message ||= master['default'] || 'None Found!' +# mytask.message ||= 'None Found!' # end # # def run -# puts @message +# puts mytask.message #=> Hello! +# puts master.default #=> Yo! +# puts mytask.default #=> Yo! (inherited from master) # end # end # -# The corresponding settings in the ProjectInfo file will then be: +# With the corresponding settings in the ProjectInfo file as: # -# default: Default text, if any. +# default: Yo! # -# myname: -# TASK: mytask -# message: Message text, if any. +# mytask: +# message: Hello! # module Reap - @registry ||= {} - - # Hash of all task classes - def self.registry ; @registry ; end - - # 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.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 include ::Config include ::FileUtils RUBY = CONFIG['ruby_install_name'] class << self + # When this class is inherited the new task is registered. + def inherited( base ) - Reap.registry[base.task_name] = base + task_list[base.task_name] = base end - def task_name ; basename.downcase ; end + def task_list + @task_list ||= {} + 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 @@ -125,10 +95,14 @@ return $PROJECT_INFO.info.key?(task_name) end true end + 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 @@ -137,15 +111,15 @@ # 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 ) - @task_only_properties ||= [] - @task_only_properties |= names.collect { |n| n.to_s } - end +# def task_only_properties ; @task_only_properties ||= [] ; end +# def task_only_property( *names ) +# @task_only_properties ||= [] +# @task_only_properties |= names.collect { |n| n.to_s } +# end end #<< class # instance methods @@ -154,17 +128,17 @@ def task_help ; self.class.task_help ; end def section_required? ; self.class.section_required? ; end #def master ; ::ProjectInfo.info ; end - def master ; @master ; end + def master ; self.class.master ; end def section ; @section ; end def task ; @task ; end def initialize( *args ) - @master = CascadingOpenObject.new( $PROJECT_INFO ) - section = @master[task_name] + #@master = CascadingOpenObject.new( $PROJECT_INFO ) + section = master[task_name] case section when Array section.each do |s| initiate( s ) end @@ -179,11 +153,11 @@ @section = CascadingOpenObject.new( section ) task_properties = {} #self.class.task_only_properties.each { |t| section[t] ||= nil } task_properties = CascadingOpenObject.new( section ) - task_properties.__parent__ = @master + task_properties.__parent__ = master @task = task_properties init #task run #task end @@ -222,9 +196,21 @@ end def sh( arg ) puts arg system arg unless $PRETEND + end + + def provide_setup_rb + return true if File.exists?( 'setup.rb') + # copy from data dir to current directory + f = File.join( Config::CONFIG['datadir'], 'reap', 'setup_rb', 'setup.rb' ) + if File.exists?(f) + File.cp( f, '.' ) + true + else + nil + end end end #class Task end #module Reap