To allow environment variables to override file-based settings, set use_env = true in your configuration. The gem will look for environment variables that match your const_name and follow the hierarchy defined by env_prefix and env_separator.
Configuration Example
If you want to use SETTINGS__SECTION__SERVER to map to Settings.section.server:
Config.setup do |config|
config.const_name = 'Settings'
config.use_env = true
config.env_prefix = 'SETTINGS'
config.env_separator = '__'
config.env_converter = :downcase
config.env_parse_values = true
end
Environment Variable Mapping
Given the environment:
SETTINGS__SECTION__SERVER_SIZE=1
SETTINGS__SECTION__SERVER=google.com
SETTINGS__SECTION__SSL_ENABLED=false
The settings will be:
Settings.section.server_size # => 1
Settings.section.server # => 'google.com'
Settings.section.ssl_enabled # => false
Note: Environment variables cannot be used to assign arrays. Also, avoid using environment variables to simultaneously assign a 'flat' value and a multi-level value to the same key (e.g., setting both BACKEND_DATABASE and BACKEND_DATABASE_USER).
Config.setup do |config|
config.use_env = true
config.env_prefix = 'SETTINGS'
config.env_separator = '__'
config.env_converter = :downcase
config.env_parse_values = true
end