Class: Athar::MetadataStack

Inherits:
Object
  • Object
show all
Defined in:
lib/athar/metadata_stack.rb

Overview

Fiber-aware metadata stack used by Athar::Context to merge nested ‘with_metadata` blocks. Storage is delegated to ActiveSupport’s IsolatedExecutionState so the stack tracks the request/job execution boundary correctly under fiber-based runtimes (Solid Queue, Falcon, etc.).

Constant Summary collapse

STATE_KEY =
:athar_metadata_stack

Class Method Summary collapse

Class Method Details

.clear!Object



28
29
30
# File 'lib/athar/metadata_stack.rb', line 28

def clear!
  ActiveSupport::IsolatedExecutionState[STATE_KEY] = []
end

.currentObject



24
25
26
# File 'lib/athar/metadata_stack.rb', line 24

def current
  stack.reduce({}) { |acc, meta| acc.merge(meta) }
end

.popObject



19
20
21
22
# File 'lib/athar/metadata_stack.rb', line 19

def pop
  stack.pop
  current
end

.push(meta) ⇒ Object



14
15
16
17
# File 'lib/athar/metadata_stack.rb', line 14

def push(meta)
  stack << meta
  current
end

.stackObject



32
33
34
# File 'lib/athar/metadata_stack.rb', line 32

def stack
  ActiveSupport::IsolatedExecutionState[STATE_KEY] ||= []
end