Class: NxtPipeline::Step
- Inherits:
-
Object
- Object
- NxtPipeline::Step
- Defined in:
- lib/nxt_pipeline/step.rb
Constant Summary collapse
- RESERVED_OPTION_KEYS =
%i[to_s unless if]
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#execution_duration ⇒ Object
readonly
Returns the value of attribute execution_duration.
-
#execution_finished_at ⇒ Object
readonly
Returns the value of attribute execution_finished_at.
-
#execution_started_at ⇒ Object
readonly
Returns the value of attribute execution_started_at.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#mapped_options ⇒ Object
readonly
Returns the value of attribute mapped_options.
-
#meta_data ⇒ Object
Returns the value of attribute meta_data.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#status ⇒ Object
Returns the value of attribute status.
- #to_s ⇒ Object
Instance Method Summary collapse
- #call(acc) ⇒ Object
-
#initialize(argument, constructor, index, pipeline, callbacks, **opts) ⇒ Step
constructor
A new instance of Step.
- #set_mapped_options(acc) ⇒ Object
Constructor Details
#initialize(argument, constructor, index, pipeline, callbacks, **opts) ⇒ Step
Returns a new instance of Step.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nxt_pipeline/step.rb', line 5 def initialize(argument, constructor, index, pipeline, callbacks, **opts) @opts = opts.symbolize_keys @pipeline = pipeline @callbacks = callbacks @argument = argument @index = index @constructor = constructor @to_s = opts.fetch(:to_s) { argument } @options_mapper = opts[:map_options] @status = nil @result = nil @error = nil @mapped_options = nil @meta_data = nil define_option_readers end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def argument @argument end |
#error ⇒ Object
Returns the value of attribute error.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def error @error end |
#execution_duration ⇒ Object
Returns the value of attribute execution_duration.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def execution_duration @execution_duration end |
#execution_finished_at ⇒ Object
Returns the value of attribute execution_finished_at.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def execution_finished_at @execution_finished_at end |
#execution_started_at ⇒ Object
Returns the value of attribute execution_started_at.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def execution_started_at @execution_started_at end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def index @index end |
#mapped_options ⇒ Object
Returns the value of attribute mapped_options.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def @mapped_options end |
#meta_data ⇒ Object
Returns the value of attribute meta_data.
36 37 38 |
# File 'lib/nxt_pipeline/step.rb', line 36 def @meta_data end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def opts @opts end |
#result ⇒ Object
Returns the value of attribute result.
25 26 27 |
# File 'lib/nxt_pipeline/step.rb', line 25 def result @result end |
#status ⇒ Object
Returns the value of attribute status.
36 37 38 |
# File 'lib/nxt_pipeline/step.rb', line 36 def status @status end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/nxt_pipeline/step.rb', line 68 def to_s @to_s.to_s end |
Instance Method Details
#call(acc) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/nxt_pipeline/step.rb', line 38 def call(acc) track_execution_time do (acc) guard_args = [acc, self] callbacks.run(:before, :step, acc) if evaluate_unless_guard(guard_args) && evaluate_if_guard(guard_args) callbacks.around(:step, acc) do set_result(acc) end end callbacks.run(:after, :step, acc) set_status result end rescue StandardError => e self.status = :failed self.error = e raise end |
#set_mapped_options(acc) ⇒ Object
62 63 64 65 66 |
# File 'lib/nxt_pipeline/step.rb', line 62 def (acc) mapper = || mapper_args = [acc, self].take(mapper.arity) self. = mapper.call(*mapper_args) end |