Module: Dotenv
- Defined in:
- lib/dotenv.rb,
lib/dotenv/cli.rb,
lib/dotenv/parser.rb,
lib/dotenv/version.rb,
lib/dotenv/environment.rb,
lib/dotenv/substitutions/command.rb,
lib/dotenv/substitutions/variable.rb
Overview
The top level Dotenv module. The entrypoint for the application logic.
Defined Under Namespace
Modules: Substitutions Classes: CLI, Environment, FormatError, Parser
Constant Summary collapse
- VERSION =
"2.4.0".freeze
Class Attribute Summary collapse
-
.instrumenter ⇒ Object
Returns the value of attribute instrumenter.
Class Method Summary collapse
- .ignoring_nonexistent_files ⇒ Object
- .instrument(name, payload = {}, &block) ⇒ Object
- .load(*filenames) ⇒ Object
-
.load!(*filenames) ⇒ Object
same as ‘load`, but raises Errno::ENOENT if any files don’t exist.
-
.overload(*filenames) ⇒ Object
same as ‘load`, but will override existing values in `ENV`.
-
.with(*filenames) ⇒ Object
Internal: Helper to expand list of filenames.
Class Attribute Details
.instrumenter ⇒ Object
Returns the value of attribute instrumenter.
7 8 9 |
# File 'lib/dotenv.rb', line 7 def instrumenter @instrumenter end |
Class Method Details
.ignoring_nonexistent_files ⇒ Object
58 59 60 61 |
# File 'lib/dotenv.rb', line 58 def ignoring_nonexistent_files yield rescue Errno::ENOENT end |
.instrument(name, payload = {}, &block) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/dotenv.rb', line 50 def instrument(name, payload = {}, &block) if instrumenter instrumenter.instrument(name, payload, &block) else yield end end |
.load(*filenames) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/dotenv.rb', line 12 def load(*filenames) with(*filenames) do |f| ignoring_nonexistent_files do env = Environment.new(f, true) instrument("dotenv.load", env: env) { env.apply } end end end |
.load!(*filenames) ⇒ Object
same as ‘load`, but raises Errno::ENOENT if any files don’t exist
22 23 24 25 26 27 |
# File 'lib/dotenv.rb', line 22 def load!(*filenames) with(*filenames) do |f| env = Environment.new(f, true) instrument("dotenv.load", env: env) { env.apply } end end |
.overload(*filenames) ⇒ Object
same as ‘load`, but will override existing values in `ENV`
30 31 32 33 34 35 36 37 |
# File 'lib/dotenv.rb', line 30 def overload(*filenames) with(*filenames) do |f| ignoring_nonexistent_files do env = Environment.new(f, false) instrument("dotenv.overload", env: env) { env.apply! } end end end |
.with(*filenames) ⇒ Object
Internal: Helper to expand list of filenames.
Returns a hash of all the loaded environment variables.
42 43 44 45 46 47 48 |
# File 'lib/dotenv.rb', line 42 def with(*filenames) filenames << ".env" if filenames.empty? filenames.reduce({}) do |hash, filename| hash.merge!(yield(File.(filename)) || {}) end end |