Class: Substation::Chain::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/substation/chain/definition.rb

Overview

Encapsulates an ordered list of Processor instances to be used within an instance of Substation::Chain

Constant Summary collapse

EMPTY =

An empty instance

new(nil, EMPTY_ARRAY).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, processors) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new instance



36
37
38
39
# File 'lib/substation/chain/definition.rb', line 36

def initialize(name, processors)
  @name, @processors = name, []
  processors.each(&method(:<<))
end

Instance Attribute Details

#nameSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The name of the chain



18
19
20
# File 'lib/substation/chain/definition.rb', line 18

def name
  @name
end

Instance Method Details

#<<(processor) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Append processor to #processors



49
50
51
52
53
# File 'lib/substation/chain/definition.rb', line 49

def <<(processor)
  raise_duplicate_processor_error([processor]) if include?(processor)
  processors << processor
  self
end

#prepend(other) ⇒ Definition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance with other's processors prepended



85
86
87
88
89
# File 'lib/substation/chain/definition.rb', line 85

def prepend(other)
  duplicates = processors & other.processors
  raise_duplicate_processor_error(duplicates) if duplicates.any?
  self.class.new(name, other.processors | processors)
end

#replace_failure_chain(processor_name, failure_chain) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Replace the failure chain of the processor identified by name



71
72
73
74
75
# File 'lib/substation/chain/definition.rb', line 71

def replace_failure_chain(processor_name, failure_chain)
  idx = fetch(processor_name)
  processors[idx] = processors.at(idx).with_failure_chain(failure_chain)
  self
end