class UltraMarathon::AbstractRunner

Private Class Methods

run(name=:main, options={}, &block) click to toggle source

This is where the magic happens. Called in the class context, it will be safely executed in the context of the instance.

@example

class BubblesRunner < AbstractRunner
  run do
    fire_the_missiles
    take_a_nap
  end

  def fire_the_missiles
    puts 'But I am le tired'
  end

  def take_a_nap
    puts 'zzzzzz'
  end
end

BubblesRunner.new.run!
# => 'But I am le tired'
# => 'zzzzzz'
# File lib/ultra_marathon/abstract_runner.rb, line 41
def run(name=:main, options={}, &block)
  name = name.to_sym
  if !run_blocks.key? name
    options[:name] = name
    self.run_blocks[name] = [options, block]
  else
    raise NameError.new("Run block named #{name} already exists!")
  end
end
run_collection(name=:main, items=[], options={}, &block) click to toggle source
# File lib/ultra_marathon/abstract_runner.rb, line 51
def run_collection(name=:main, items=[], options={}, &block)
  options.merge!(collection: true, items: items)
  run(name, options, &block)
end

Private Instance Methods

new_sub_runner(options, block) click to toggle source

Creates a new sub runner, defaulting the context to `self`

# File lib/ultra_marathon/abstract_runner.rb, line 71
def new_sub_runner(options, block)
  options = {
    context: self,
    collection: false,
    items: []
  }.merge(options)
  if options[:collection]
    CollectionRunner.new(options.delete(:items), options, &block)
  else
    SubRunner.new(options, block)
  end
end
unrun_sub_runners() click to toggle source

Memoizes the sub runners based on the run blocks and their included options.

# File lib/ultra_marathon/abstract_runner.rb, line 61
def unrun_sub_runners
  @unrun_sub_runners ||= begin
    self.class.run_blocks.reduce(Store.new) do |runner_store, (_name, (options, block))|
      runner_store << new_sub_runner(options, block)
      runner_store
    end
  end
end
write_log() click to toggle source
# File lib/ultra_marathon/abstract_runner.rb, line 84
def write_log
  log_all_sub_runners
  log_summary
end