Class: Substation::Chain::DSL

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

Overview

The DSL class used to define chains in an Environment

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Parameters:

  • processors (#each<#call>)

    an enumerable of processors to build on top of

  • block (Proc)

    a block to be instance_eval’ed



131
132
133
134
135
# File 'lib/substation/chain/dsl.rb', line 131

def initialize(processors, &block)
  @processors = []
  chain(processors)
  instance_eval(&block) if block
end

Instance Attribute Details

#processorsArray<#call> (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 processors to be used within a Substation::Chain

Returns:



103
104
105
# File 'lib/substation/chain/dsl.rb', line 103

def processors
  @processors
end

Class Method Details

.processors(chain, &block) ⇒ Array<#call>

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 processors to be used within a Substation::Chain

Parameters:

  • chain (Chain)

    the chain to build on top of

  • block (Proc)

    a block to be instance_eval’ed

Returns:



116
117
118
# File 'lib/substation/chain/dsl.rb', line 116

def self.processors(chain, &block)
  new(chain, &block).processors
end

Instance Method Details

#chain(other) ⇒ 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.

Nest the given chain within another one

Parameters:

  • other (#each<#call>)

    another chain to be nested within a chain

Returns:

  • (self)


158
159
160
161
# File 'lib/substation/chain/dsl.rb', line 158

def chain(other)
  other.each { |handler| use(handler) }
  self
end

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

Use the given processor within a chain

Parameters:

  • processor (#call)

    a processor to use within a chain

Returns:

  • (self)


145
146
147
148
# File 'lib/substation/chain/dsl.rb', line 145

def use(processor)
  @processors << processor
  self
end