lib/tap/task.rb in bahuvrihi-tap-0.10.3 vs lib/tap/task.rb in bahuvrihi-tap-0.10.4

- old
+ new

@@ -177,10 +177,12 @@ child.instance_variable_set(:@default_name, child.to_s.underscore) child.instance_variable_set(:@dependencies, dependencies.dup) super end + # Returns an instance of self; the instance is a kind of 'global' + # instance used in class-level dependencies. See depends_on. def instance @instance ||= new end # Generates or updates the specified subclass of self. @@ -214,12 +216,11 @@ subclass.define_process(block) if block_given? # # Register documentation # - - const_name = current == Object ? subclass_const : "#{current}::#{subclass_const}" + const_name = subclass.to_s caller.each_with_index do |line, index| case line when /\/tap\/support\/declarations.rb/ then next when Support::Lazydoc::CALLER_REGEXP subclass.source_file = File.expand_path($1) @@ -332,10 +333,13 @@ } def help Tap::Support::Templater.new(DEFAULT_HELP_TEMPLATE, :task_class => self).build end + # Sets a class-level dependency. When task class B depends_on another task + # class A, instances of B are initialized to depend on A.instance, with the + # specified arguments. Returns self. def depends_on(dependency_class, *args) unless dependency_class.respond_to?(:instance) raise ArgumentError, "dependency_class does not respond to instance: #{dependency_class}" end (dependencies << [dependency_class, args]).uniq! @@ -347,10 +351,11 @@ def dependency(name, dependency_class, *args) depends_on(dependency_class, *args) define_method(name) do index = Support::Executable.index(dependency_class.instance, args) + Support::Executable.resolve([index]) Support::Executable.results[index]._current end public(name) end @@ -392,12 +397,12 @@ raise ArgumentError, "cannot define configurations from: #{configs}" end end def define_dependencies(dependencies) - dependencies.each do |name, dependency_class, *args| - dependency(name, dependency_class, *args) + dependencies.each do |name, dependency_class, args| + dependency(name, dependency_class, *(args ? args : [])) end if dependencies end def define_process(block) send(:define_method, :process, &block) @@ -433,11 +438,10 @@ @app = app @name = name || self.class.default_name @task_block = (task_block == nil ? default_task_block : task_block) @_method_name = :execute - @multithread = false @on_complete_block = nil @dependencies = [] case config when Support::InstanceConfiguration @@ -466,13 +470,43 @@ # of inputs specified by the arity of the _method_name method. def enq(*inputs) app.queue.enq(self, inputs) end - batch_function :enq, :multithread= + batch_function :enq batch_function(:on_complete) {} + # Convenience method, equivalent to: + # self.app.sequence([self] + tasks) + def sequence(*tasks) + app.sequence([self] + tasks) + end + + # Convenience method, equivalent to: + # self.app.fork(self, targets) + def fork(*targets) + app.fork(self, targets) + end + + # Convenience method, equivalent to: + # self.app.merge(self, sources) + def merge(*sources) + app.merge(self, sources) + end + + # Convenience method, equivalent to: + # self.app.sync_merge(self, sources) + def sync_merge(*sources) + app.sync_merge(self, sources) + end + + # Convenience method, equivalent to: + # self.app.switch(self, targets, &block) + def switch(*targets, &block) + app.switch(self, targets, &block) + end + # Executes self with the given inputs. Execute provides hooks for subclasses # to insert standard execution code: before_execute, on_execute_error, # and after_execute. Override any/all of these methods as needed. # # Execute passes the inputs to process and returns the result. @@ -545,9 +579,15 @@ end # Returns self.name def to_s name.to_s + end + + # Provides an abbreviated version of the default inspect, with only + # the task class, object_id, name, and configurations listed. + def inspect + "#<#{self.class.to_s}:#{object_id} #{name} #{config.to_hash.inspect} >" end protected # Hook to set a default task block. By default, nil. \ No newline at end of file