Module: TrackRelay::Manifest
- Defined in:
- lib/track_relay/manifest.rb
Overview
Generate a typed JSON manifest of the loaded catalog for the ‘@track_relay/client` JS package (Plan 02-05) to fetch and validate events client-side. The on-disk artifact is written by either:
* `rake track_relay:manifest` (production / CI), or
* `config.to_prepare` in development (regenerated on every reload),
both of which delegate to Manifest.write!. The generated shape is stable and consumed by the JS client:
{
"version": "<gem version>",
"generated_at": "<ISO8601 timestamp>",
"events": {
"<event_name>": {
"params": {"<param>" => "<type>"}, # all 5 ParamSchema types
"required": ["<required_param_name>"] # may be []
}
}
}
Phase 2 ships ‘params` (types) + `required[]` only — richer constraints (max/in/format) land in Phase 4 alongside generators.
Constant Summary collapse
- DEFAULT_FILENAME =
"track_relay_catalog.json"
Class Method Summary collapse
-
.generate(catalog: Catalog) ⇒ Hash
Build the manifest Hash from a catalog-like object.
-
.write!(path: default_path, catalog: Catalog) ⇒ String, Pathname
Write the manifest to ‘path` as pretty-printed JSON.
Class Method Details
.generate(catalog: Catalog) ⇒ Hash
Build the manifest Hash from a catalog-like object.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/track_relay/manifest.rb', line 43 def generate(catalog: Catalog) { version: TrackRelay::VERSION, generated_at: Time.now.utc.iso8601, events: catalog.all.each_with_object({}) do |defn, h| h[defn.name.to_s] = { params: defn.params.transform_keys(&:to_s).transform_values { |s| s.type.to_s }, required: defn.params.select { |_, s| s.required }.keys.map(&:to_s) } end } end |
.write!(path: default_path, catalog: Catalog) ⇒ String, Pathname
Write the manifest to ‘path` as pretty-printed JSON.
‘FileUtils.mkdir_p(File.dirname(path))` is called first so a fresh checkout (e.g. the Combustion dummy app at `test/internal/`, which has no `public/` directory) does NOT crash with `Errno::ENOENT` on the first call.
68 69 70 71 72 |
# File 'lib/track_relay/manifest.rb', line 68 def write!(path: default_path, catalog: Catalog) FileUtils.mkdir_p(File.dirname(path)) File.write(path, JSON.pretty_generate(generate(catalog: catalog))) path end |