Class: StandardHealth::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_controllerObject

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_specObject

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_controllerObject

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

#checksArray<Registration>

Returns frozen view of registered checks.

Returns:

  • (Array<Registration>)

    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.

Parameters:

  • name (Symbol)

    short identifier surfaced in /ready output

  • klass (Class)

    subclass of StandardHealth::Check

  • critical (Boolean) (defaults to: false)

    failure flips overall status to :unavailable



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