Class: Trailblazer::Context
- Inherits:
-
Object
- Object
- Trailblazer::Context
- Defined in:
- lib/trailblazer/context.rb
Overview
only public creator: Build
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #Build ⇒ 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(, ) , = , end |
Instance Method Details
#[](name) ⇒ Object
32 33 34 |
# File 'lib/trailblazer/context.rb', line 32 def [](name) [name] || [name] end |
#[]=(name, value) ⇒ Object
36 37 38 |
# File 'lib/trailblazer/context.rb', line 36 def []=(name, value) [name] = value end |
#Build ⇒ Object
67 68 69 70 71 72 |
# File 'lib/trailblazer/context.rb', line 67 def Build , = *decompose = yield(, ) if block_given? Trailblazer::Context() end |
#decompose ⇒ Object
Return the Context’s two components. Used when computing the new output for the next activity.
48 49 50 51 52 |
# File 'lib/trailblazer/context.rb', line 48 def decompose # it would be cool if that could "destroy" the original object. # also, if those hashes were immutable, that'd be amazing. [ , ] 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.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/trailblazer/context.rb', line 56 def to_hash {}.tap do |hash| # arr = to_runtime_data << to_mutable_data << tmp_options # the "key" here is to call to_hash on all containers. [ .to_hash, .to_hash ].each do || .each { |k, v| hash[k.to_sym] = v } end end end |