Class: Pdi::Spoon
- Inherits:
-
Object
- Object
- Pdi::Spoon
- Defined in:
- lib/pdi/spoon.rb,
lib/pdi/spoon/parser.rb,
lib/pdi/spoon/result.rb,
lib/pdi/spoon/options.rb,
lib/pdi/spoon/pan_error.rb,
lib/pdi/spoon/options/arg.rb,
lib/pdi/spoon/kitchen_error.rb,
lib/pdi/spoon/options/level.rb,
lib/pdi/spoon/options/param.rb
Overview
This class is the main wrapper for PDI’s pan and kitchen scripts.
Defined Under Namespace
Classes: KitchenError, Options, PanError, Parser, Result
Constant Summary collapse
- DEFAULT_KITCHEN =
'kitchen.sh'- DEFAULT_PAN =
'pan.sh'- TYPES_TO_ERRORS =
{ Options::Type::JOB => KitchenError, Options::Type::TRANSFORMATION => PanError }.freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#executor ⇒ Object
readonly
Returns the value of attribute executor.
-
#kitchen ⇒ Object
readonly
Returns the value of attribute kitchen.
-
#pan ⇒ Object
readonly
Returns the value of attribute pan.
Instance Method Summary collapse
-
#initialize(args: [], dir:, kitchen: DEFAULT_KITCHEN, pan: DEFAULT_PAN, timeout_in_seconds: nil) ⇒ Spoon
constructor
A new instance of Spoon.
-
#run(options, &streaming_reader) ⇒ Object
Returns a
Pdi::Executor::Resultinstance when PDI returns error code 0 or else raises a PanError (transformation) or KitchenError (job). -
#version ⇒ Object
Returns a Spoon::Result instance when PDI returns error code 0 or else raises a KitchenError since Kitchen was used to run the version command.
Constructor Details
#initialize(args: [], dir:, kitchen: DEFAULT_KITCHEN, pan: DEFAULT_PAN, timeout_in_seconds: nil) ⇒ Spoon
Returns a new instance of Spoon.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pdi/spoon.rb', line 29 def initialize( args: [], dir:, kitchen: DEFAULT_KITCHEN, pan: DEFAULT_PAN, timeout_in_seconds: nil ) assert_required(:dir, dir) assert_required(:kitchen, kitchen) assert_required(:pan, pan) @args = Array(args) @dir = File.(dir.to_s) @kitchen = kitchen.to_s @pan = pan.to_s @executor = Executor.new(timeout_in_seconds: timeout_in_seconds) @parser = Parser.new freeze end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
27 28 29 |
# File 'lib/pdi/spoon.rb', line 27 def args @args end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
27 28 29 |
# File 'lib/pdi/spoon.rb', line 27 def dir @dir end |
#executor ⇒ Object (readonly)
Returns the value of attribute executor.
27 28 29 |
# File 'lib/pdi/spoon.rb', line 27 def executor @executor end |
#kitchen ⇒ Object (readonly)
Returns the value of attribute kitchen.
27 28 29 |
# File 'lib/pdi/spoon.rb', line 27 def kitchen @kitchen end |
#pan ⇒ Object (readonly)
Returns the value of attribute pan.
27 28 29 |
# File 'lib/pdi/spoon.rb', line 27 def pan @pan end |
Instance Method Details
#run(options, &streaming_reader) ⇒ Object
Returns a Pdi::Executor::Result instance when PDI returns error code 0 or else raises a PanError (transformation) or KitchenError (job).
An optional block may be passed in so that the output of a run is available in a streaming manner during the run. This block takes one parameter which is the current chunk of output and is called repeatedly throughout the run.
70 71 72 73 74 75 76 77 |
# File 'lib/pdi/spoon.rb', line 70 def run(, &streaming_reader) = Options.make() all_args = run_args() executor.run(all_args, &streaming_reader).tap do |result| raise(error_constant(), result) if result.code != 0 end end |
#version ⇒ Object
Returns a Spoon::Result instance when PDI returns error code 0 or else raises a KitchenError since Kitchen was used to run the version command.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pdi/spoon.rb', line 52 def version final_args = [kitchen_path] + args + [Options::Arg.new(Options::Arg::Key::VERSION)] result = executor.run(final_args) version_line = parser.version(result.out) raise(KitchenError, result) if result.code != 0 Result.new(result, version_line) end |