Class: UltraMarathon::AbstractRunner

Inherits:
BaseRunner show all
Defined in:
lib/ultra_marathon/abstract_runner.rb

Constant Summary

Constants inherited from BaseRunner

BaseRunner::RUN_INSTRUMENTATION_NAME

Instance Attribute Summary

Attributes inherited from BaseRunner

#success

Class Method Summary collapse

Methods inherited from BaseRunner

new, #reset, #run!, #run_instrumentation, #success?

Methods included from Contexticution

#contexticute

Methods included from Instrumentation

#instrumentations

Methods included from Logging

#logger

Class Method Details

.run(name = :main, options = {}, &block) ⇒ Object

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

Examples:

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'


41
42
43
44
45
46
47
48
49
# 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) ⇒ Object



51
52
53
54
# 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