Class: QED::Evaluator

Inherits:
Object show all
Defined in:
lib/qed/evaluator.rb

Overview

Demonstrandum Evaluator is responsible for running demo scripts.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(demo, options = {}) ⇒ Evaluator

Setup new evaluator instance.

Parameters:

  • demo (Demo) —

    The demo to run.

  • options (Hash) (defaults to: {}) —

    a customizable set of options

Options Hash (options):

  • :applique (Boolean) —

    Is this applique code?

  • :observers (Array) —

    Objects that respond to observable interface. Typically this is just a Reporter instance.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/qed/evaluator.rb', line 26

def initialize(demo, options={})
  @demo  = demo
  @steps = demo.steps

  #@settings  = options[:settings]
  @applique  = options[:applique]  # BOOLEAN FLAG

  @observers = options[:observers].to_a
  @observers += applique_observers

  @scope     = options[:scope] || Scope.new(demo)
end

Instance Attribute Details

#demo ⇒ Demo (readonly)

The Demo being evaluated.

Returns:



57
58
59
# File 'lib/qed/evaluator.rb', line 57

def demo
  @demo
end

#observers ⇒ Object (readonly)

The observers.



61
62
63
# File 'lib/qed/evaluator.rb', line 61

def observers
  @observers
end

Class Method Details

.run(demo, options = {}) ⇒ Object

Create new Evaluator instance and then run it.



10
11
12
# File 'lib/qed/evaluator.rb', line 10

def self.run(demo, options={})
  new(demo, options).run
end

Instance Method Details

#applique_observers ⇒ Object

Collect applique all the signal-based advice and wrap their evaluation in observable procedure calls.



42
43
44
45
46
47
48
49
50
# File 'lib/qed/evaluator.rb', line 42

def applique_observers
  demo = @demo
  demo.applique.map do |a|
    Proc.new do |type, *args|
      proc = a.__signals__[type.to_sym] 
      @scope.instance_exec(*args, &proc) if proc
    end
  end
end

#run ⇒ Object

Run the demo.



65
66
67
68
69
70
71
72
73
# File 'lib/qed/evaluator.rb', line 65

def run
  advise!(:before_demo, @demo)
  begin
    advise!(:demo, @demo)
    run_steps
  ensure
    advise!(:after_demo, @demo)
  end
end