Module: Smplkit::RequestContext

Defined in:
lib/smplkit/context.rb

Overview

Per-request context stash for context-sensitive evaluation (flags today, likely more later).

Backed by per-Fiber storage (Ruby 3.2+) which falls through to per-Thread storage when not running under a Fiber scheduler. This gives proper per-request isolation under both threaded and fiber-based concurrency.

Constant Summary collapse

KEY =
:smplkit_request_context

Class Method Summary collapse

Class Method Details

.getObject



15
16
17
# File 'lib/smplkit/context.rb', line 15

def get
  Thread.current[KEY] || []
end

.reset(previous) ⇒ Object



25
26
27
# File 'lib/smplkit/context.rb', line 25

def reset(previous)
  Thread.current[KEY] = previous
end

.set(contexts) ⇒ Object



19
20
21
22
23
# File 'lib/smplkit/context.rb', line 19

def set(contexts)
  previous = Thread.current[KEY]
  Thread.current[KEY] = contexts.dup.freeze
  previous
end