Class: Trailblazer::Context
- Inherits:
-
Object
- Object
- Trailblazer::Context
- Defined in:
- lib/trailblazer/context.rb
Overview
only public creator: Build
Defined Under Namespace
Classes: ContainerChain
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
-
#decompose ⇒ Object
Return the Context’s two components.
-
#initialize(wrapped_options, mutable_options) ⇒ Context
constructor
:data object:.
- #merge(hash) ⇒ Object
-
#to_hash ⇒ Object
TODO: massive performance bottleneck.
Constructor Details
#initialize(wrapped_options, mutable_options) ⇒ Context
:data object:
28 29 30 |
# File 'lib/trailblazer/context.rb', line 28 def initialize(, ) @wrapped_options, @mutable_options = , end |
Instance Method Details
#[](name) ⇒ Object
32 33 34 |
# File 'lib/trailblazer/context.rb', line 32 def [](name) ContainerChain.find( [@mutable_options, @wrapped_options], name ) end |
#[]=(name, value) ⇒ Object
36 37 38 |
# File 'lib/trailblazer/context.rb', line 36 def []=(name, value) @mutable_options[name] = value end |
#decompose ⇒ Object
Return the Context’s two components. Used when computing the new output for the next activity.
48 49 50 |
# File 'lib/trailblazer/context.rb', line 48 def decompose [ @wrapped_options, @mutable_options ] end |
#merge(hash) ⇒ Object
40 41 42 43 44 |
# File 'lib/trailblazer/context.rb', line 40 def merge(hash) original, = decompose ctx = Trailblazer::Context( original, .merge(hash) ) end |
#to_hash ⇒ Object
TODO: massive performance bottleneck. also, we could already “know” here what keys the transformation wants. FIXME: ToKeywordArguments()
58 59 60 61 62 63 64 65 |
# File 'lib/trailblazer/context.rb', line 58 def to_hash {}.tap do |hash| # the "key" here is to call to_hash on all containers. [ @wrapped_options.to_hash, @mutable_options.to_hash ].each do || .each { |k, v| hash[k.to_sym] = v } end end end |