instance method
dotenvs
Ruby on Rails edge
Since edgeSignature
dotenvs(path = Rails.root.join(".env"))
Returns an ActiveSupport::DotEnvConfiguration instance that provides access to the variables in .env through symbol-based lookup with explicit methods for required and optional values. This is the same interface offered by #envs and can be accessed in a combined manner via #creds.
The .env file format supports:
-
Lines with KEY=value pairs
-
Comments starting with #
-
Empty lines (ignored)
-
Quoted values (single or double quotes)
-
Variable interpolation with ${VAR} syntax
-
Commandexecution with $(command) syntax
Examples:
Rails.app.dotenvs.require(:db_password) # DB_PASSWORD from .env
Rails.app.dotenvs.require(:aws, :access_key_id) # AWS__ACCESS_KEY_ID from .env
Rails.app.dotenvs.option(:cache_host) # CACHE_HOST from .env or nil
Rails.app.dotenvs.option(:cache_host, default: "cache-host-1") # CACHE_HOST from .env or "cache-host-1"
Rails.app.dotenvs.option(:cache_host, default: -> { HostProvider.cache }) # CACHE_HOST from .env or HostProvider.cache
In development mode, this configuration backend is automatically part of Rails.app.creds.
Parameters
-
pathopt = Rails.root.join(".env")
Source
# File railties/lib/rails/application.rb, line 584
def dotenvs(path = Rails.root.join(".env"))
@dotenvs ||= {}
@dotenvs[path] ||= ActiveSupport::DotEnvConfiguration.new(path)
end
Defined in railties/lib/rails/application.rb line 584
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Rails::Application