Module: Shipeasy::SDK::Env
- Defined in:
- lib/shipeasy/sdk/env.rb
Overview
Native runtime-environment detection.
Used ONLY to pick the DEFAULT for outbound egress when the caller does not set it explicitly:
- is the SDK allowed to make network requests at all (is_network_enabled)?
- is per-evaluation usage telemetry allowed (disable_telemetry)?
Both default to ON in production and OFF everywhere else, so a local/dev/CI run of an app that embeds the SDK never phones home unless it explicitly opts in.
Precedence for the production decision (mirrors the TS SDK's src/env.ts):
1. A native runtime env var — SHIPEASY_ENV, then RAILS_ENV, then RACK_ENV,
then APP_ENV. A value of "production"/"prod" (case-insensitive) ⇒ prod;
anything else present ("development"/"staging"/"test"/…) ⇒ not prod.
2. When no native env var is set (e.g. serverless / some containers), fall
back to the SDK's OWN configured `env` option, which the caller sets and
which itself defaults to "prod". This keeps a real production deploy
"on" by default while an `env: "dev"` config stays quiet.
The env option is always present (it defaults to "prod"), so the production decision is always inferrable — the SDK never has to make the field required.
Constant Summary collapse
- NATIVE_ENV_VARS =
Native env vars consulted, in precedence order.
%w[SHIPEASY_ENV RAILS_ENV RACK_ENV APP_ENV].freeze
Class Method Summary collapse
-
.is_production_env(configured_env = nil) ⇒ Object
True when the host runtime looks like a production deployment.
-
.read_native_env ⇒ Object
Read the first present native env var (lowercased, trimmed), or nil when none of them is set to a non-empty value.
Class Method Details
.is_production_env(configured_env = nil) ⇒ Object
True when the host runtime looks like a production deployment.
configured_env is the SDK's own env option (dev/staging/prod); it is
consulted ONLY when no native runtime env var is set.
34 35 36 37 38 39 |
# File 'lib/shipeasy/sdk/env.rb', line 34 def is_production_env(configured_env = nil) native = read_native_env return native == "production" || native == "prod" unless native.nil? (configured_env || "prod").to_s.strip.downcase == "prod" end |
.read_native_env ⇒ Object
Read the first present native env var (lowercased, trimmed), or nil when none of them is set to a non-empty value.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/shipeasy/sdk/env.rb', line 43 def read_native_env NATIVE_ENV_VARS.each do |name| raw = ENV[name] next if raw.nil? v = raw.strip.downcase return v unless v.empty? end nil end |