class Urist::Runner

Attributes

active_scenario[RW]
done_scenarios[RW]
information[RW]
log[RW]
result[RW]

Public Class Methods

new(options={}) click to toggle source
# File lib/urist/runner.rb, line 6
def initialize options={}
  @information     = options[:information] || {}
  @active_scenario = options[:startup_scenario]
  @done_scenarios  = []
  @log             = []

  validate!
end

Public Instance Methods

go!() click to toggle source
# File lib/urist/runner.rb, line 15
def go!
  run_active_scenario while @active_scenario

  return @result
end

Private Instance Methods

assign_next_scenario!() click to toggle source
# File lib/urist/runner.rb, line 30
def assign_next_scenario!
  decision = @result[:decision]
  @active_scenario = @active_scenario.links[decision]
end
check_for_duplicate_scenario!() click to toggle source

raise an exception if detected that scripts start looping

# File lib/urist/runner.rb, line 49
def check_for_duplicate_scenario!
  if @done_scenarios.include? @active_scenario
    raise RuntimeError, "Current scenario has already been passed. Current #{@active_scenario.inspect}. Previous #{@done_scenarios.last}"
  else
    @done_scenarios << @active_scenario
  end
end
execute_active_scenario!() click to toggle source
# File lib/urist/runner.rb, line 44
def execute_active_scenario!
  @result = @active_scenario.new(:information => @information).logic
end
log_result!() click to toggle source
# File lib/urist/runner.rb, line 35
def log_result!
  @log << @result
end
run_active_scenario() click to toggle source
# File lib/urist/runner.rb, line 22
def run_active_scenario
  check_for_duplicate_scenario!
  execute_active_scenario!
  validate_result!
  log_result!
  assign_next_scenario!
end
validate!() click to toggle source
# File lib/urist/runner.rb, line 57
def validate!
  raise ArgumentError, ":information should be assigned. #{@information.inspect} given." if @information.nil?
  raise ArgumentError, ":startup_scenario should be assigned. #{@active_scenario.inspect} given." if @active_scenario.nil?
end
validate_result!() click to toggle source
# File lib/urist/runner.rb, line 39
def validate_result!
  raise ArgumentError, "Incorrect 'result' in #{@active_scenario.inspect}. Result must be returned as Hash." unless @result.is_a? Hash
  raise ArgumentError, "Incorrect 'result' in #{@active_scenario.inspect}. Result must include ':decision' key." unless @result.has_key? :decision
end