module ENV
Overview
ENV
is a hash-like accessor for environment variables.
Example
# Set env var PORT to a default if not already set
ENV["PORT"] ||= "5000"
# Later use that env var.
puts ENV["PORT"].to_i
NOTE All keys and values are strings. You must take care to cast other types at runtime, e.g. integer port numbers.
Extended Modules
- Enumerable({String, String})
Defined in:
secrets-env.crConstant Summary
-
DEFAULT_SECRETS_PATH =
"/run/secrets"
Class Method Summary
-
.fetch(key : String, &block : String -> String | Nil)
Retrieves a value corresponding to a given key.
-
.fetch_secret(key : String, &block : String -> String | Nil)
Retrieves a value corresponding to the given key.
-
.has_key?(key : String) : Bool
Returns
true
if the environment variable named key exists or an secrets file of the same name is available. -
.has_secret?(key : String) : Bool
Returns
true
if the secret named key exists.
Class Method Detail
Retrieves a value corresponding to a given key. The value will be retrieved from (in order of priorities): system env vars, available secrets files or the return value of the block.
This override the default ENV module behaviour to support reading of secrets injected to an environment from docker-compose, kubernetes and other orchestration tools.
Retrieves a value corresponding to the given key. Return the value of the block if the key does not exist.
Returns true
if the environment variable named key exists or an secrets
file of the same name is available.