Class: NurseAndrea::EnvironmentDetector
- Inherits:
-
Object
- Object
- NurseAndrea::EnvironmentDetector
- Defined in:
- lib/nurse_andrea/environment_detector.rb
Overview
Resolves the deployment environment via a fixed precedence chain (high → low, first match wins):
1. explicit value set in SDK init (the override — most intentional)
2. hosting-platform metadata (Railway env name — deployment-tier truth)
3. process declared env (RAILS_ENV / RACK_ENV / APP_ENV — weakest)
4. default: "unknown" — NEVER masquerade as production
“unknown” is a display-only value: when nothing resolves, the SDK transmits “unknown” verbatim; the server stores it; the UI shows “UNKNOWN”. It is NOT an operational environment.
The taxonomy is development / staging / production (local ⇒ development). Unmappable values (custom platform env names, “test”, etc.) do not masquerade — they fall through the chain toward “unknown”.
Constant Summary collapse
- SUPPORTED =
%w[production staging development].freeze
- UNKNOWN =
"unknown"- PROCESS_VARS =
Process-env vars consulted, in order (Ruby / Rack conventions).
%w[RAILS_ENV RACK_ENV APP_ENV].freeze
Class Method Summary collapse
-
.detect(explicit = nil) ⇒ Object
The resolved environment value (string).
- .reset_warning! ⇒ Object
-
.resolve(explicit = nil) ⇒ Object
Full resolution detail: { value:, source:, variable_name: }.
Class Method Details
.detect(explicit = nil) ⇒ Object
The resolved environment value (string). Backward-compatible entry point used by Configuration#initialize. ‘explicit` is the optional tier-1 override (Configuration also supports a post-init override).
26 27 28 |
# File 'lib/nurse_andrea/environment_detector.rb', line 26 def detect(explicit = nil) resolve(explicit).fetch(:value) end |
.reset_warning! ⇒ Object
56 57 58 |
# File 'lib/nurse_andrea/environment_detector.rb', line 56 def reset_warning! @warned = false end |
.resolve(explicit = nil) ⇒ Object
Full resolution detail: { value:, source:, variable_name: }. ‘source` is which tier won (explicit/platform/process/default); `variable_name` is the env-var NAME read (never its value). Both are privacy-safe metadata for the ingest payload — see DATA_PRIVACY_POLICY.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nurse_andrea/environment_detector.rb', line 34 def resolve(explicit = nil) if (value = normalize(explicit)) return detail(value, "explicit", nil) end platform_env = PlatformDetector.context[:environment] if (value = normalize(platform_env)) return detail(value, "platform", PlatformDetector.environment_variable_name) end PROCESS_VARS.each do |var| raw = ENV[var] next if raw.nil? || raw.empty? if (value = normalize(raw)) return detail(value, "process", var) end warn_unsupported(raw, var) # present but unmappable — keep resolving end detail(UNKNOWN, "default", nil) end |