Class: NxtPipeline::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_pipeline/step.rb

Constant Summary collapse

RESERVED_OPTION_KEYS =
%i[to_s unless if]

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argumentObject (readonly)

Returns the value of attribute argument.



25
26
27
# File 'lib/nxt_pipeline/step.rb', line 25

def argument
  @argument
end

#errorObject

Returns the value of attribute error.



25
26
27
# File 'lib/nxt_pipeline/step.rb', line 25

def error
  @error
end

#execution_durationObject

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_atObject

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_atObject

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

#indexObject (readonly)

Returns the value of attribute index.



25
26
27
# File 'lib/nxt_pipeline/step.rb', line 25

def index
  @index
end

#mapped_optionsObject

Returns the value of attribute mapped_options.



25
26
27
# File 'lib/nxt_pipeline/step.rb', line 25

def mapped_options
  @mapped_options
end

#meta_dataObject

Returns the value of attribute meta_data.



36
37
38
# File 'lib/nxt_pipeline/step.rb', line 36

def 
  @meta_data
end

#optsObject (readonly)

Returns the value of attribute opts.



25
26
27
# File 'lib/nxt_pipeline/step.rb', line 25

def opts
  @opts
end

#resultObject

Returns the value of attribute result.



25
26
27
# File 'lib/nxt_pipeline/step.rb', line 25

def result
  @result
end

#statusObject

Returns the value of attribute status.



36
37
38
# File 'lib/nxt_pipeline/step.rb', line 36

def status
  @status
end

#to_sObject



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
    set_mapped_options(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 set_mapped_options(acc)
  mapper = options_mapper || default_options_mapper
  mapper_args = [acc, self].take(mapper.arity)
  self.mapped_options = mapper.call(*mapper_args)
end