Class: TrackRelay::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/track_relay/railtie.rb

Overview

Rails integration boundary for the gem.

Three responsibilities, all wired in initializer blocks:

1. Tell Zeitwerk to ignore `Rails.root/config/track_relay` so that
 DSL files in that directory (which call {TrackRelay.catalog}
 rather than defining constants) don't trip Rails autoloading.

2. Register a `config.to_prepare` callback that calls
 {Catalog.clear!} and then `Dir.glob/load`s every `*.rb` file
 under `config/track_relay/`. {Catalog.clear!} runs FIRST so
 editing a catalog file in dev produces a clean rebuild rather
 than a duplicate-registration error from {Catalog#register}.
 `to_prepare` runs once at boot in test/production and before
 every request reload in development — exactly the hot-reload
 contract this gem needs.

3. Call {Dispatcher.start!} exactly once via
 `config.after_initialize` so the AS::Notifications fan-out
 subscription is registered before the host app handles its
 first request. {Dispatcher.start!} is idempotent so this is
 safe even when the Railtie is loaded multiple times.

The Railtie is required from lib/track_relay.rb only when Rails::Railtie is defined, so the gem still loads cleanly in non-Rails contexts (plain require "track_relay" from a script).