class Shellout::Task

Public Class Methods

new() { |self| ... } click to toggle source

For executing sub tasks in correct order, we depend on the fact that hash iteration is in insert order

# File lib/shellout/task.rb, line 7
def initialize
  @sub_tasks    = {}
  @on_call_done = ->{}
  yield self if block_given?
end

Public Instance Methods

add_sub_task(name, sub) click to toggle source
# File lib/shellout/task.rb, line 18
def add_sub_task(name, sub)
  @sub_tasks[name.to_sym] = sub
end
call() click to toggle source
# File lib/shellout/task.rb, line 32
def call
  @results = {}
  @sub_tasks.each do |k, sub|
    @results[k] = sub.call
  end
  @on_call_done.call
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/shellout/task.rb, line 13
def method_missing(name, *args)
  super unless name =~ /=$/
  add_sub_task(name.to_s.chop, args.first)
end
on_call_done(&callback) click to toggle source
# File lib/shellout/task.rb, line 28
def on_call_done(&callback)
  @on_call_done = callback
end
printf(format) click to toggle source
Calls superclass method
# File lib/shellout/task.rb, line 22
def printf(format)
  @sub_tasks['printf'] = -> do
    super(format, @results)
  end
end