Class: Rhales::HydrationRegistry
- Inherits:
-
Object
- Object
- Rhales::HydrationRegistry
- Defined in:
- lib/rhales/hydration_registry.rb
Overview
Registry to track window attributes used in hydration blocks within a single request. Prevents silent data overwrites.
Class Method Summary collapse
-
.clear! ⇒ Object
-
.register(window_attr, template_path, merge_strategy = nil) ⇒ Object
-
.registry ⇒ Object
Expose registry for testing purposes.
-
.thread_local_registry ⇒ Object
private
-
.validate_inputs(window_attr, template_path) ⇒ Object
private
Class Method Details
.clear! ⇒ Object
28 29 30 |
# File 'lib/rhales/hydration_registry.rb', line 28 def clear! Thread.current[:rhales_hydration_registry] = {} end |
.register(window_attr, template_path, merge_strategy = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rhales/hydration_registry.rb', line 8 def register(window_attr, template_path, merge_strategy = nil) validate_inputs(window_attr, template_path) registry = thread_local_registry if registry[window_attr] && merge_strategy.nil? existing = registry[window_attr] raise HydrationCollisionError.new( window_attr, existing[:path], template_path, ) end registry[window_attr] = { path: template_path, merge_strategy: merge_strategy, } end |
.registry ⇒ Object
Expose registry for testing purposes
33 34 35 |
# File 'lib/rhales/hydration_registry.rb', line 33 def registry thread_local_registry end |
.thread_local_registry ⇒ Object (private)
39 40 41 |
# File 'lib/rhales/hydration_registry.rb', line 39 def thread_local_registry Thread.current[:rhales_hydration_registry] ||= {} end |
.validate_inputs(window_attr, template_path) ⇒ Object (private)
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rhales/hydration_registry.rb', line 43 def validate_inputs(window_attr, template_path) if window_attr.nil? raise ArgumentError, 'window attribute cannot be nil' end if window_attr.empty? raise ArgumentError, 'window attribute cannot be empty' end if template_path.nil? raise ArgumentError, 'template path cannot be nil' end end |