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 35 |
# File 'lib/trailblazer/context.rb', line 32 def [](name) return [name] if .key?(name) [name] end |
#[]=(name, value) ⇒ Object
37 38 39 |
# File 'lib/trailblazer/context.rb', line 37 def []=(name, value) [name] = value end |
#Build ⇒ Object
68 69 70 71 72 73 |
# File 'lib/trailblazer/context.rb', line 68 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.
49 50 51 52 53 |
# File 'lib/trailblazer/context.rb', line 49 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
41 42 43 44 45 |
# File 'lib/trailblazer/context.rb', line 41 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.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/trailblazer/context.rb', line 57 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 |