Class Tap::Task
In: lib/tap/task.rb
Parent: App::Api

Tasks are nodes that map to the command line. Tasks provide support for configuration, documentation, and provide helpers to build workflows.


Tasks are configurable. By default each task will be configured as specified in the class definition. Configurations may be accessed through config, or through accessors.

  class ConfiguredTask < Tap::Task
    config :one, 'one'
    config :two, 'two'

  t =
  t.config                     # => {:one => 'one', :two => 'two'}                        # => 'one' = 'ONE'
  t.config                     # => {:one => 'ONE', :two => 'two'}

Overrides and even unspecified configurations may be provided during initialization. Unspecified configurations do not have accessors.

  t = => 'ONE', :three => 'three')
  t.config                     # => {:one => 'ONE', :two => 'two', :three => 'three'}
  t.respond_to?(:three)        # => false

Configurations can be validated/transformed using an optional block. Many common blocks are pre-packaged and may be accessed through the class method ‘c’:

  class ValidatingTask < Tap::Task
    # string config validated to be a string
    config :string, 'str', &c.check(String)

    # integer config; string inputs are converted using YAML
    config :integer, 1, &c.yaml(Integer)

  t =
  t.string = 1                 # !> ValidationError
  t.integer = 1.1              # !> ValidationError

  t.integer = "1"
  t.integer == 1               # => true

See the Configurable documentation for more information.


Tasks may be subclassed normally, but be sure to call super as necessary, in particular when overriding the following methods:

  class Subclass < Tap::Task
    class << self
      def inherited(child)

    def initialize(*args)

    def initialize_copy(orig)


associations   call   enq   exe   log   new   on_complete   parser   process  


joins  [R]  An array of joins for self

Public Class methods


     # File lib/tap/task.rb, line 99
 99:     def initialize(config={}, app=Tap::App.current)
100:       @app = app
101:       @joins = []
102:       initialize_config(config)
103:     end


    # File lib/tap/task.rb, line 77
77:       def parser(app)
78:         opts = super
80:         # add option to specify a config file

81:         opts.on('--config FILE', 'Specifies a config file') do |config_file|
82:           configs = Configurable::Utils.load_file(config_file, true)
83:           opts.config.merge!(configs)
84:         end
86:         opts
87:       end

Public Instance methods

Returns the associations array: [nil, joins]


     # File lib/tap/task.rb, line 161
161:     def associations
162:       [nil, joins]
163:     end

Call splats the input to process and exists to provide subclasses a way to wrap process behavior.


     # File lib/tap/task.rb, line 107
107:     def call(input)
108:       process(*input)
109:     end

Enques self with an array of inputs (directly use app.enq to enque with a non-array input, or override in a subclass).


     # File lib/tap/task.rb, line 139
139:     def enq(*args)
140:       app.enq(self, args)
141:     end

Executes self with an array of inputs (directly use app.exe to execute with a non-array input, or override in a subclass).


     # File lib/tap/task.rb, line 145
145:     def exe(*args)
146:       app.exe(self, args)
147:     end

Logs the inputs to the application logger (via app.log)


     # File lib/tap/task.rb, line 150
150:     def log(action, msg=nil, level=Logger::INFO)
151:       app.log(action, msg, level) { yield }
152:     end

Sets the block as a join for self.


     # File lib/tap/task.rb, line 155
155:     def on_complete(&block) # :yields: result

156:       joins << block if block
157:       self
158:     end

The method for processing inputs into outputs. Override this method in subclasses to provide class-specific process logic. The arguments given to enq/exe should correspond to the arguments required by process. The process return is the result passed to joins.

  class TaskWithTwoInputs < Tap::Task
    def process(a, b)

  results = []
  app =

  task ={}, app)
  task.on_complete {|result| results << result }
  results                 # => [[2,1], [4,3]]

By default, process simply returns the inputs.


     # File lib/tap/task.rb, line 133
133:     def process(*inputs)
134:       inputs
135:     end