Class: Acta::Upcaster::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/acta/upcaster.rb

Overview

Per-replay state carrier passed to every upcaster block. Hash-shaped by default — ‘context ||= {}`. Lives the length of one replay; never persisted across runs.

Defined Under Namespace

Classes: FailReplay

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



74
75
76
# File 'lib/acta/upcaster.rb', line 74

def initialize
  @store = {}
end

Instance Method Details

#[](key) ⇒ Object



78
79
80
# File 'lib/acta/upcaster.rb', line 78

def [](key)
  @store[key] ||= {}
end

#[]=(key, value) ⇒ Object



82
83
84
# File 'lib/acta/upcaster.rb', line 82

def []=(key, value)
  @store[key] = value
end

#fail_replay!(reason) ⇒ Object

Halt the replay with a clear reason. Wrapped by the pipeline into ‘Acta::ReplayHaltedByUpcaster`, which carries the offending record.

Raises:



92
93
94
# File 'lib/acta/upcaster.rb', line 92

def fail_replay!(reason)
  raise FailReplay, reason
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/acta/upcaster.rb', line 86

def key?(key)
  @store.key?(key)
end