Class: Substation::Environment

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/substation/environment.rb,
lib/substation/environment/dsl.rb

Overview

The environment holding all registered Chain processors

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_env, actions, chain_dsl) ⇒ 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



73
74
75
76
77
78
# File 'lib/substation/environment.rb', line 73

def initialize(app_env, actions, chain_dsl)
  @app_env   = app_env
  @actions   = actions
  @chain_dsl = chain_dsl
  @registry  = chain_dsl.registry
end

Instance Attribute Details

#actionsDispatcher::Registry (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 mutable action registry



55
56
57
# File 'lib/substation/environment.rb', line 55

def actions
  @actions
end

#app_envObject (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 application environment



48
49
50
# File 'lib/substation/environment.rb', line 48

def app_env
  @app_env
end

Class Method Details

.build(app_env, actions = Dispatcher.new_registry, &block) ⇒ Environment

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::Environment instance



25
26
27
# File 'lib/substation/environment.rb', line 25

def self.build(app_env, actions = Dispatcher.new_registry, &block)
  new(app_env, actions, chain_dsl(&block))
end

Instance Method Details

#[](name) ⇒ 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.

Return the chain identified by name or raise an error

Raises:



147
148
149
# File 'lib/substation/environment.rb', line 147

def [](name)
  actions.fetch(name)
end

#chain(name = nil, other = Chain::EMPTY, exception_chain = Chain::EMPTY, &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 Chain instance



112
113
114
# File 'lib/substation/environment.rb', line 112

def chain(name = nil, other = Chain::EMPTY, exception_chain = Chain::EMPTY, &block)
  @chain_dsl.build(name, other, exception_chain, &block)
end

#dispatcherDispatcher

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 Dispatcher instance

See Also:

  • Dispatcher.new


161
162
163
# File 'lib/substation/environment.rb', line 161

def dispatcher
  Dispatcher.new(actions, app_env)
end

#inherit(app_env = app_env, actions = Dispatcher.new_registry, &block) ⇒ Environment

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.

Inherit a new instance from self, merging the Chain::DSL



91
92
93
# File 'lib/substation/environment.rb', line 91

def inherit(app_env = app_env, actions = Dispatcher.new_registry, &block)
  self.class.new(app_env, actions, merged_chain_dsl(&block))
end

#register(name, other = Chain::EMPTY, exception_chain = Chain::EMPTY, &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.

Register a new chain under the given name



131
132
133
134
# File 'lib/substation/environment.rb', line 131

def register(name, other = Chain::EMPTY, exception_chain = Chain::EMPTY, &block)
  actions[name] = chain(name, other, exception_chain, &block)
  self
end