Class: Simmer::Externals::SpoonClient

Inherits:
Object
  • Object
show all
Defined in:
lib/simmer/externals/spoon_client.rb,
lib/simmer/externals/spoon_client/result.rb

Overview

Wraps up Pdi::Spoon at a higher-level for Simmer to consume.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files_dir, spoon) ⇒ SpoonClient

Returns a new instance of SpoonClient.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
# File 'lib/simmer/externals/spoon_client.rb', line 18

def initialize(files_dir, spoon)
  raise ArgumentError, 'spoon is required' unless spoon

  @files_dir = files_dir.to_s
  @spoon     = spoon

  freeze
end

Instance Attribute Details

#spoonObject (readonly)

Returns the value of attribute spoon.



16
17
18
# File 'lib/simmer/externals/spoon_client.rb', line 16

def spoon
  @spoon
end

Instance Method Details

#run(specification, config, &output_capturer) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/simmer/externals/spoon_client.rb', line 27

def run(specification, config, &output_capturer)
  execution_result = nil
  time_in_seconds  = nil

  begin
    time_in_seconds = Benchmark.measure do
      execution_result = execute!(specification, config, &output_capturer)
    end.real
  rescue Pdi::Spoon::PanError, Pdi::Spoon::KitchenError => e
    return Result.new(
      message: "PDI execution returned an error: #{e.class.name} (#{e.execution.code})",
      execution_result: e.execution,
      time_in_seconds: time_in_seconds
    )
  end

  Result.new(
    execution_result: execution_result,
    time_in_seconds: time_in_seconds
  )
end