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.



33
34
35
36
37
# File 'lib/standard_health/configuration.rb', line 33

def initialize
  @parent_controller = "ActionController::API"
  @env_spec = nil
  @checks = []
end

Instance Attribute Details

#env_specObject

An optional ‘StandardHealth::EnvSpec` instance describing required and recommended environment variables for the host app. Audited via the /diagnostics/env endpoint.



31
32
33
# File 'lib/standard_health/configuration.rb', line 31

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



49
50
51
# File 'lib/standard_health/configuration.rb', line 49

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



44
45
46
# File 'lib/standard_health/configuration.rb', line 44

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.



55
56
57
# File 'lib/standard_health/configuration.rb', line 55

def reset_checks!
  @checks = []
end