Class: Lutaml::Model::AdapterScope
- Inherits:
-
Object
- Object
- Lutaml::Model::AdapterScope
- Defined in:
- lib/lutaml/model/adapter_scope.rb
Overview
Thread-local scoped adapter override stack.
Provides block-scoped adapter overrides for testing and library stacking. Each thread has its own stack — no mutex needed.
Constant Summary collapse
- STACK_KEY =
:__lutaml_adapter_scope_stack- EMPTY =
{}.freeze
Class Method Summary collapse
-
.current ⇒ Hash{Symbol => Symbol}
Return the current scope’s overrides hash.
-
.override_for(format) ⇒ Symbol?
Return the override for a specific format from the current scope.
-
.reset! ⇒ void
Clear all scope state (for testing reset).
-
.with(overrides) { ... } ⇒ Object
Push adapter overrides and yield.
Class Method Details
.current ⇒ Hash{Symbol => Symbol}
Return the current scope’s overrides hash.
44 45 46 |
# File 'lib/lutaml/model/adapter_scope.rb', line 44 def self.current Thread.current[STACK_KEY]&.last || EMPTY end |
.override_for(format) ⇒ Symbol?
Return the override for a specific format from the current scope.
52 53 54 |
# File 'lib/lutaml/model/adapter_scope.rb', line 52 def self.override_for(format) current[format] end |
.reset! ⇒ void
This method returns an undefined value.
Clear all scope state (for testing reset).
59 60 61 |
# File 'lib/lutaml/model/adapter_scope.rb', line 59 def self.reset! Thread.current[STACK_KEY] = nil end |
.with(overrides) { ... } ⇒ Object
Push adapter overrides and yield. Restores previous scope on exit.
32 33 34 35 36 37 38 39 |
# File 'lib/lutaml/model/adapter_scope.rb', line 32 def self.with(overrides) stack = Thread.current[STACK_KEY] ||= [] stack.push(overrides) yield ensure stack.pop Thread.current[STACK_KEY] = nil if stack.empty? end |