Class: Ruact::ServerFunctions::Registry
- Inherits:
-
Object
- Object
- Ruact::ServerFunctions::Registry
- Defined in:
- lib/ruact/server_functions/registry.rb
Overview
In-memory storage for server-function entries. One instance backs ‘Ruact.action_registry`; another backs `Ruact.query_registry` — kept separate so the JSON snapshot can emit a `kind` field per entry without the call sites having to thread an extra parameter through. Cross-registry JS-identifier collisions are detected by Snapshot at snapshot time (a single registry only sees its own entries).
Thread-safety: not thread-safe by design. Registration happens at controller-class load time (‘config.to_prepare` in dev, eager-load in production), single-threaded. Reads from #entries return a frozen snapshot of the internal hash so concurrent readers cannot observe a partial registration.
Constant Summary collapse
- ALLOWED_KINDS =
The only kinds the codegen knows how to emit. Story 8.1 owns ‘:action`, Story 9.1 owns `:query`. Any other value is rejected at registration time — silent acceptance would otherwise let an unknown kind fall through and be emitted as an action signature.
%i[action query].freeze
Instance Method Summary collapse
-
#clear! ⇒ self
Wipes the registry.
-
#empty? ⇒ Boolean
Whether the registry has no entries.
-
#entries ⇒ Hash{Symbol => Ruact::ServerFunctions::RegistryEntry}
Frozen snapshot of the current entries, ordered by insertion.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(symbol, kind:, controller: nil) { ... } ⇒ Ruact::ServerFunctions::RegistryEntry
Adds
symbolto the registry. -
#size ⇒ Integer
Number of registered entries.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
24 25 26 |
# File 'lib/ruact/server_functions/registry.rb', line 24 def initialize @entries = {} end |
Instance Method Details
#clear! ⇒ self
Wipes the registry. Used by ‘config.to_prepare` (between dev reloads) and by tests that need a clean slate.
69 70 71 72 |
# File 'lib/ruact/server_functions/registry.rb', line 69 def clear! @entries.clear self end |
#empty? ⇒ Boolean
Returns whether the registry has no entries.
80 81 82 |
# File 'lib/ruact/server_functions/registry.rb', line 80 def empty? @entries.empty? end |
#entries ⇒ Hash{Symbol => Ruact::ServerFunctions::RegistryEntry}
Returns frozen snapshot of the current entries, ordered by insertion.
61 62 63 |
# File 'lib/ruact/server_functions/registry.rb', line 61 def entries @entries.dup.freeze end |
#register(symbol, kind:, controller: nil) { ... } ⇒ Ruact::ServerFunctions::RegistryEntry
Adds symbol to the registry.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruact/server_functions/registry.rb', line 43 def register(symbol, kind:, controller: nil, &block) validate_kind!(symbol, kind, controller) js_identifier = translate_symbol(symbol, controller) detect_collision!(symbol, js_identifier, controller) entry = RegistryEntry.new( ruby_symbol: symbol, js_identifier: js_identifier, kind: kind, controller: controller, block: block ) @entries[symbol] = entry entry end |
#size ⇒ Integer
Returns number of registered entries.
75 76 77 |
# File 'lib/ruact/server_functions/registry.rb', line 75 def size @entries.size end |