Module: Ruact::ServerFunctions::Snapshot
- Defined in:
- lib/ruact/server_functions/snapshot.rb
Overview
Pure functions that build the JSON-shaped Hash representing the route-
driven server-function bridge. Serialized to
tmp/cache/ruact/server-functions.json by Snapshot.generate_v2!; the Vite
plugin reads that file and emits the TS module.
Story 9.9 — the v1 registry path was demolished; only the route-driven (version-2) schema remains.
Constant Summary collapse
- VERSION_V2 =
Story 9.3 — the route-driven snapshot schema. v2 entries are produced by RouteSource (route table), not registries.
2
Class Method Summary collapse
-
.dump_v2(entries, now: Time.now.utc) ⇒ Hash
Story 9.3 — wraps route-derived
entriesinto a version-2 snapshot Hash (the shape Codegen.render dispatches on). -
.generate_v2!(entries:, path:, now: Time.now.utc) ⇒ Boolean
Story 9.3 — write-if-changed for the route-driven (v2) bridge.
Class Method Details
.dump_v2(entries, now: Time.now.utc) ⇒ Hash
Story 9.3 — wraps route-derived entries into a version-2 snapshot
Hash (the shape Codegen.render dispatches on). Pure.
26 27 28 29 30 31 32 |
# File 'lib/ruact/server_functions/snapshot.rb', line 26 def dump_v2(entries, now: Time.now.utc) { version: VERSION_V2, generated_at: now.utc.iso8601, functions: entries } end |
.generate_v2!(entries:, path:, now: Time.now.utc) ⇒ Boolean
Story 9.3 — write-if-changed for the route-driven (v2) bridge.
generated_at is freshly stamped only when the entries changed, so a
stable route table never churns the file (and never re-triggers
downstream TS rendering). A schema mismatch (version) forces a
rewrite even when entries are unchanged.
43 44 45 46 47 48 49 |
# File 'lib/ruact/server_functions/snapshot.rb', line 43 def generate_v2!(entries:, path:, now: Time.now.utc) existing_version, existing_functions = read_existing_snapshot(path) return false if existing_version == VERSION_V2 && existing_functions == entries snapshot = { version: VERSION_V2, generated_at: now.utc.iso8601, functions: entries } SnapshotWriter.write_if_changed!(path: path, content: "#{JSON.pretty_generate(snapshot)}\n") end |