lib/reap/task.rb in reap-0.4.0 vs lib/reap/task.rb in reap-0.5.0

- old
+ new

@@ -1,42 +1,80 @@ require 'rbconfig' module Reap + # Base class for all tasks. # - # Base class for all tasks + # When creating a specifc task, subclass this one and create two class-level + # methods #task and #desc. #task will return the name of the task and + # #desc a description of the task. Then create an instance method called + # #setup to do any initial preping. Usually that means assigning + # some instance vars from the Reapfile configutration. You can use + # section[<name>] for settings from the task's particular section (as + # determined by self.task method above) and/or use master[<name>] + # for top-level settings. Finally write a #run method that preforms the + # actual task. # + # Here's an oh so simple example: + # + # class MyTask < Task + # def self.task ; 'mytask' ; end + # def self.desc ; 'This is my first custom task.' ; end + # + # def setup + # @message = section['message'] || master['default'] || 'None Found!' + # end + # + # def run + # puts @message + # end + # end + # + # This corresponding settings in the Reapfile will then be: + # + # default: Default text, if any. + # + # mytask: + # message: Message text, if any. + # + # Reap automatically handles multiple task runs if an array is provided + # under the task section instead of a single mapping. For example: + # + # mytask: + # - + # message: First Run. + # - + # message: Second Run. + # class Task RUBY = Config::CONFIG['ruby_install_name'] - DEFAULT_INCLUDE = [ '[A-Z]*', 'setup.rb', 'lib/**/*', 'bin/**/*', + DEFAULT_INCLUDE = [ '[A-Z]*', 'setup.rb', 'lib/**/*', 'bin/**/*', 'data/**/*', 'doc/**/*', 'rdoc/**/*', 'test/**/*', 'bench/**/*', 'demo/**/*', 'samples/**/*', 'examples/**/*' ] MUST_EXCLUDE = [ 'InstalledFiles', '**/CVS/**/*', '**/*~' ] - - def self.inherited( klass ) - (@task_registry ||= []) << klass + class << self + def inherited( klass ) + (@task_registry ||= []) << klass + end + def registry ; @task_registry ||= [] ; end + def tasks ; @task ||= registry.collect { |t| t.task } ; end end - - def self.registry ; @task_registry ||= [] ; end - def self.tasks ; @task ||= registry.collect { |t| t.task } ; end + attr_reader :master, :section - - attr_reader :config, :section - - def initialize( config ) - @config = config + def initialize( master_config, section_config ) + @master = master_config + @section = section_config + setup if respond_to?(:setup) end - def [](x) - @config[x] - end + def [](x) ; @section[x] ; end # Run the system command +cmd+. # # Example: # sh %{ls -ltr} @@ -46,11 +84,11 @@ FileUtils.send( :fu_output_message, cmd ) if options[:verbose] unless options[:noop] system(cmd) or fail "Command Failed: [#{cmd}]" end end - + # Run a Ruby interpreter with the given arguments. # # Example: # ruby %{-pe '$_.upcase!' <README} # @@ -61,11 +99,11 @@ options = {} end puts "#{RUBY} #{args.join(' ')}" if $DEBUG sh "#{RUBY} #{args.join(' ')}", options end - + # # Attempt to do a normal file link, but fall back # # to a copy if the link fails. # def safe_ln(*args) # if @link_not_supported # FileUtils.cp(*args) @@ -76,28 +114,39 @@ # @link_not_supported = true # FileUtils.cp(*args) # end # end # end - + # Returns the full package name which combines package name and version. def package_name - @config['name'] + '--' + ( @config['version'] || '0.0.1' ) + @config['name'] + '-' + ( @config['version'] || '0.0.1' ) end - + # def rakefile # s = '' # rf = File.join(locate, 'packmule', 'packmule.rake') # File.open( rf ) { |f| s << f.gets(nil) } # s # end - # + # # def yamlform # s = '' # yf = File.join(locate, 'packmule', 'packmule.yaml') # File.open( yf ) { |f| s << f.gets(nil) } # s # end + + #def value( key, *alt_masters ) + # return section[key] if section.key?( key ) + # alt_masters.each do |path| + # parr = path.split(':').collect { |e| e.downcase } + # conf = @config + # parr.each { |e| conf = conf[e] } + # return conf if conf + # end + # nil + #end end end #module Reap