Module: Datacraft::Runner

Included in:
Datacraft
Defined in:
lib/datacraft/runner.rb

Overview

The runner for the whole process

Instance Method Summary collapse

Instance Method Details

#run(instruction) ⇒ Object

run the instruction



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/datacraft/runner.rb', line 7

def run(instruction)
  @inst = instruction
  measurements = []

  # run pre_build hooks
  if @inst.respond_to? :pre_hooks
    measurements << Benchmark.measure('pre build:') do
      @inst.pre_hooks.each(&:call)
    end
  end

  # process the rows
  measurements << Benchmark.measure('process rows:') do
    @inst.options[:parallel] ? pprocess_rows : process_rows
  end

  # build
  measurements << Benchmark.measure('build:') do
    build @inst.consumers
  end

  # run post_build hooks
  if @inst.respond_to? :post_hooks
    measurements << Benchmark.measure('post build:') do
      @inst.post_hooks.each(&:call)
    end
  end
  report measurements if @inst.options[:benchmark]
end