Class: Trailblazer::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/context.rb

Overview

only public creator: Build

Defined Under Namespace

Classes: ContainerChain

Instance Method Summary collapse

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)
  @wrapped_options, @mutable_options = 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

#decomposeObject

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, mutable_options = decompose

  ctx = Trailblazer::Context( original, mutable_options.merge(hash) )
end

#to_hashObject

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 |options|
      options.each { |k, v| hash[k.to_sym] = v }
    end
  end
end