Class: Substation::Chain::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/substation/chain/dsl.rb,
lib/substation/chain/dsl/config.rb,
lib/substation/chain/dsl/module_builder.rb

Overview

The DSL class used to define chains in an Environment

Defined Under Namespace

Classes: Config, ModuleBuilder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, definition) ⇒ 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

Extends the new instance with methods defined in config.dsl_module. Only happens during boot, once for every instantiated Environment.

Parameters:



68
69
70
71
72
73
74
75
# File 'lib/substation/chain/dsl.rb', line 68

def initialize(config, definition)
  @config     = config
  @definition = definition
  @registry   = @config.registry
  @name       = @definition.name

  extend(@config.dsl_module)
end

Instance Attribute Details

#configConfig (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 config for this instance

Returns:



38
39
40
# File 'lib/substation/chain/dsl.rb', line 38

def config
  @config
end

#definitionDefinition (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 definition to be used within a Substation::Chain

Returns:



45
46
47
# File 'lib/substation/chain/dsl.rb', line 45

def definition
  @definition
end

#name#to_sym (readonly)

The chain's name

Returns:

  • (#to_sym)


31
32
33
# File 'lib/substation/chain/dsl.rb', line 31

def name
  @name
end

#registryHash<Symbol, Processor::Builder> (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 registry used to build processors

Returns:



52
53
54
# File 'lib/substation/chain/dsl.rb', line 52

def registry
  @registry
end

Class Method Details

.build(registry, definition = Definition::EMPTY) ⇒ DSL

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.

Build a new instance suitable for registry

Parameters:

Returns:



20
21
22
# File 'lib/substation/chain/dsl.rb', line 20

def self.build(registry, definition = Definition::EMPTY)
  new(Config.build(registry), definition)
end

Instance Method Details

#build(name, other, exception_chain, &block) ⇒ Chain

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.

Build a new Substation::Chain based on other, a failure_chain and a block

Parameters:

  • name (#to_sym)

    the name of the chain to build

  • other (Enumerable<#call>)

    the processors to prepend

  • exception_chain (Chain)

    the chain to invoke in case of an uncaught exception

  • block (Proc)

    a block to be instance_eval'ed inside the new Substation::Chain::DSL instance

Returns:



94
95
96
# File 'lib/substation/chain/dsl.rb', line 94

def build(name, other, exception_chain, &block)
  Chain.new(__call__(Definition.new(name, other), &block), exception_chain)
end

#chain(processors, &block) ⇒ 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 the given chain

Parameters:

Returns:

  • (self)


106
107
108
109
110
# File 'lib/substation/chain/dsl.rb', line 106

def chain(processors, &block)
  processors.each(&method(:use))
  instance_eval(&block) if block
  self
end

#failure_chain(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.

Use chain as the failure chain for the processor identified by name

Parameters:

  • name (Symbol)

    the processor's name

  • failure_chain (Chain)

    the failure chain to use for the processor identified by name

Returns:

  • (self)


142
143
144
145
# File 'lib/substation/chain/dsl.rb', line 142

def failure_chain(name, failure_chain)
  definition.replace_failure_chain(name, failure_chain)
  self
end

#nest(name, chain, executor) ⇒ Processor::Nest::Incoming

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.

Nest the given chain at the end of the current one

Parameters:

  • name (#to_sym)

    the name of the nested chain

  • chain (Enumerable<#call>)

    the chain to nest

  • executor (Processor::Executor)

    the executor used for nesting

Returns:



126
127
128
129
# File 'lib/substation/chain/dsl.rb', line 126

def nest(name, chain, executor)
  config = Processor::Config.new(executor, EMPTY_ARRAY, EMPTY_ARRAY)
  use(Processor::Nest::Incoming.new(name, chain, config))
end