Module: Dotenv
- Defined in:
- lib/dotenv.rb,
lib/dotenv/parser.rb,
lib/dotenv/version.rb,
lib/dotenv/environment.rb,
lib/dotenv/substitutions/command.rb,
lib/dotenv/substitutions/variable.rb
Defined Under Namespace
Modules: Substitutions Classes: Environment, FormatError, Parser
Constant Summary collapse
- VERSION =
'1.0.2'
Class Method Summary collapse
- .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, &block) ⇒ Object
Internal: Helper to expand list of filenames.
Class Method Details
.load(*filenames) ⇒ Object
5 6 7 |
# File 'lib/dotenv.rb', line 5 def self.load(*filenames) with(*filenames) { |f| Environment.new(f).apply if File.exist?(f) } end |
.load!(*filenames) ⇒ Object
same as ‘load`, but raises Errno::ENOENT if any files don’t exist
10 11 12 |
# File 'lib/dotenv.rb', line 10 def self.load!(*filenames) with(*filenames) { |f| Environment.new(f).apply } end |
.overload(*filenames) ⇒ Object
same as ‘load`, but will override existing values in `ENV`
15 16 17 |
# File 'lib/dotenv.rb', line 15 def self.overload(*filenames) with(*filenames) { |f| Environment.new(f).apply! if File.exist?(f) } end |
.with(*filenames, &block) ⇒ Object
Internal: Helper to expand list of filenames.
Returns a hash of all the loaded environment variables.
22 23 24 25 26 27 28 29 30 |
# File 'lib/dotenv.rb', line 22 def self.with(*filenames, &block) filenames << '.env' if filenames.empty? {}.tap do |hash| filenames.each do |filename| hash.merge! block.call(File.(filename)) || {} end end end |