module Dotenv
Extended Modules
Defined in:
dotenv.crClass Method Summary
-
.strict : Bool
Raises an exception on parsing error.
-
.strict=(strict : Bool)
Raises an exception on parsing error.
Instance Method Summary
-
#load(filename : Path | String = ".env", override_keys : Bool = false) : Hash(String, String)
Loads environment variables from a file into the
ENV
constant. -
#load(io : IO, override_keys : Bool = false) : Hash(String, String)
Loads environment variables from an
IO
into theENV
constant. -
#load(hash : Hash(String, String), override_keys : Bool = false) : Hash(String, String)
Loads a Hash of environment variables into the
ENV
constant. -
#load?(filename : Path | String = ".env", override_keys : Bool = false) : Hash(String, String) | Nil
Loads environment variables from a file into the
ENV
constant if the file is present, else returnsnil
. -
#load_string(env_vars : String, override_keys : Bool = false) : Hash(String, String)
Loads environment variables from a
String
into theENV
constant. -
#parse(env_vars : String | IO) : Hash(String, String)
Parses a
.env
formattedString
/IO
data, and returns a hash (without loading it toENV
).
Class Method Detail
Instance Method Detail
Loads environment variables from a file into the ENV
constant.
require "dotenv"
File.write ".env-file", "VAR=Hello"
Dotenv.load ".env-file" # => {"VAR" => "Hello"}
Dotenv.load ".absent-file" # => No such file or directory (Errno)
Loads environment variables from an IO
into the ENV
constant.
require "dotenv"
hash = Dotenv.load IO::Memory.new("VAR=Hello")
hash # => {"VAR" => "Hello"}
Loads a Hash of environment variables into the ENV
constant.
require "dotenv"
Dotenv.load({"VAR" => "test"})
Loads environment variables from a file into the ENV
constant
if the file is present, else returns nil
.
require "dotenv"
File.write ".env-file", "VAR=Hello"
Dotenv.load? ".env-file" # => {"VAR" => "Hello"}
Dotenv.load? ".not-present" # => nil
Loads environment variables from a String
into the ENV
constant.
require "dotenv"
hash = Dotenv.load_string "VAR=Hello"
hash # => {"VAR" => "Hello"}
Parses a .env
formatted String
/IO
data, and returns a hash (without loading it to ENV
).
require "dotenv"
hash = Dotenv.parse "VAR=Hello"
hash # => {"VAR" => "Hello"}