Class: StandardHealth::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- StandardHealth::Generators::InstallGenerator
- Defined in:
- lib/generators/standard_health/install/install_generator.rb
Overview
Installs StandardHealth in a host Rails application.
Writes config/initializers/standard_health.rb and mounts the engine in
config/routes.rb.
The routes step exists because of a failure mode that is otherwise
invisible: the engine only draws SUB-paths (/alive, /ready,
/diagnostics/env), so an app that mounts it and expects an aggregate
GET /health silently has no aggregate tier — no boot error, no failing
route spec. The generated block carries the ordering requirement as a
comment right where someone will read it.
Idempotent: re-running skips pieces already installed. --skip-* opts
out of individual steps; --force overwrites an existing initializer.
Constant Summary collapse
- INITIALIZER_PATH =
"config/initializers/standard_health.rb"- ROUTES_PATH =
"config/routes.rb"
Instance Method Summary collapse
Instance Method Details
#copy_initializer ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/standard_health/install/install_generator.rb', line 46 def copy_initializer if [:skip_initializer] say_status("skip", "#{INITIALIZER_PATH} (--skip-initializer)", :yellow) return end if File.exist?(File.join(destination_root, INITIALIZER_PATH)) && ![:force] say_status("identical", "#{INITIALIZER_PATH} (already exists; pass --force to overwrite)", :blue) return end template "initializer.rb.erb", INITIALIZER_PATH, force: [:force] end |
#mount_engine ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/generators/standard_health/install/install_generator.rb', line 60 def mount_engine if [:skip_routes] say_status("skip", "#{ROUTES_PATH} (--skip-routes)", :yellow) return end unless routes_file_exists? say_status("skip", "#{ROUTES_PATH} not found; mount the engine manually", :yellow) return end if already_mounted? say_status("identical", "#{ROUTES_PATH} (engine already mounted), skipping", :blue) return end route(routes_snippet) return unless aggregate_route_drawn? # `route` prepends, so a host that already draws its own `GET /health` # ends up with the mount ABOVE it. That still WORKS — the engine draws # no bare `/health`, so its router returns X-Cascade: pass and the # outer route matches (there is a spec pinning this). But it reads # backwards against the documented ordering, so say so rather than # leaving them to wonder. say_status( "review", "#{ROUTES_PATH}: the mount was prepended ABOVE your existing `GET /health`. " \ "It still resolves via route cascading, but move the mount below it to match " \ "the documented ordering.", :yellow ) end |