Class: RailsPodKit::Config

Inherits:
Anyway::Config
  • Object
show all
Defined in:
lib/rails_pod_kit/config.rb

Overview

Backed by anyway_config: every attribute can also come from RAILS_POD_KIT_* env vars or an optional config/rails_pod_kit.yml in the host, with the RailsPodKit.configure block (running last, from an initializer) winning over both. A single instance is memoized on the module.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(overrides = nil) ⇒ Config

Returns a new instance of Config.



75
76
77
78
79
80
81
82
83
84
# File 'lib/rails_pod_kit/config.rb', line 75

def initialize(overrides = nil)
  super

  # Env/YAML sources deliver the policy as a string; the API is symbols.
  self.sidekiq_global_metrics = sidekiq_global_metrics.to_sym if sidekiq_global_metrics
  # Dynamic defaults anyway_config can't express statically.
  self.enabled = self.class.default_enabled? if enabled.nil?
  self.port ||= Integer(ENV.fetch('PROMETHEUS_EXPORTER_PORT', DEFAULT_PORT))
  self.puma_control_url ||= ENV.fetch('PUMA_CONTROL_URL', 'tcp://127.0.0.1:9293')
end

Class Method Details

.default_enabled?Boolean

True unless we're clearly in a test environment. Kept independent of Rails so the gem's own specs (which don't load the host app) get a safe default and never bind a socket.

Returns:

  • (Boolean)


93
94
95
96
# File 'lib/rails_pod_kit/config.rb', line 93

def self.default_enabled?
  env = ENV['RAILS_ENV'] || ENV['RACK_ENV']
  env != 'test'
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/rails_pod_kit/config.rb', line 86

def enabled?
  !!enabled
end