Class: StandardHealth::Configuration
- Inherits:
-
Object
- Object
- StandardHealth::Configuration
- Defined in:
- lib/standard_health/configuration.rb
Overview
Holds engine-wide configuration.
Host apps configure the engine via:
StandardHealth.configure do |c|
c.parent_controller = "ApplicationController"
c.register_check :custom, MyCheck, critical: true
c.env_spec = StandardHealth::EnvSpec.define { ... }
end
Defined Under Namespace
Classes: Registration
Instance Attribute Summary collapse
-
#diagnostics_parent_controller ⇒ Object
Optional class name of a controller that ONLY ‘DiagnosticsController` should inherit from.
-
#env_spec ⇒ Object
An optional ‘StandardHealth::EnvSpec` instance describing required and recommended environment variables for the host app.
-
#parent_controller ⇒ Object
Class name of the controller that StandardHealth’s controllers should inherit from.
Instance Method Summary collapse
-
#checks ⇒ Array<Registration>
Frozen view of registered checks.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_check(name, klass, critical: false) ⇒ Object
Register a health check class.
-
#reset_checks! ⇒ Object
Remove all registered checks.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
45 46 47 48 49 50 |
# File 'lib/standard_health/configuration.rb', line 45 def initialize @parent_controller = "ActionController::API" @diagnostics_parent_controller = nil @env_spec = nil @checks = [] end |
Instance Attribute Details
#diagnostics_parent_controller ⇒ Object
Optional class name of a controller that ONLY ‘DiagnosticsController` should inherit from. When set, `HealthController` continues to use `parent_controller` while `DiagnosticsController` uses this one. Lets host apps put auth (e.g. HTTP Basic) on the diagnostics endpoint without needing to set `raise_on_missing_callback_actions = false` to suppress Rails 7.1’s missing-action error caused by a single parent declaring ‘before_action :auth, only: :env` for both controllers.
When unset (the default), ‘DiagnosticsController` falls back to `parent_controller` — fully backward-compatible with v0.1.0.
38 39 40 |
# File 'lib/standard_health/configuration.rb', line 38 def diagnostics_parent_controller @diagnostics_parent_controller end |
#env_spec ⇒ Object
An optional ‘StandardHealth::EnvSpec` instance describing required and recommended environment variables for the host app. Audited via the /diagnostics/env endpoint.
43 44 45 |
# File 'lib/standard_health/configuration.rb', line 43 def env_spec @env_spec end |
#parent_controller ⇒ Object
Class name of the controller that StandardHealth’s controllers should inherit from. Resolved lazily via ‘constantize` at request time so the host app’s controller (which may pull in auth concerns) is fully loaded before we touch it. Defaults to ‘ActionController::API` so the engine works in API-only host apps without configuration.
26 27 28 |
# File 'lib/standard_health/configuration.rb', line 26 def parent_controller @parent_controller end |
Instance Method Details
#checks ⇒ Array<Registration>
Returns frozen view of registered checks.
62 63 64 |
# File 'lib/standard_health/configuration.rb', line 62 def checks @checks.dup end |
#register_check(name, klass, critical: false) ⇒ Object
Register a health check class.
57 58 59 |
# File 'lib/standard_health/configuration.rb', line 57 def register_check(name, klass, critical: false) @checks << Registration.new(name: name.to_sym, klass: klass, critical: critical) end |
#reset_checks! ⇒ Object
Remove all registered checks. Mainly useful in tests where the host app and the engine share a process.
68 69 70 |
# File 'lib/standard_health/configuration.rb', line 68 def reset_checks! @checks = [] end |