Sha256: bb1974824c29783d4a6e62a09dcf3c7012fe1ece72812781b384a4ecf85324db

Contents?: true

Size: 693 Bytes

Versions: 5

Compression:

Stored size: 693 Bytes

Contents

require 'dotenv/environment'

module Dotenv
  def self.load(*filenames)
    default_if_empty(filenames).inject({}) do |hash, filename|
      filename = File.expand_path filename
      hash.merge(File.exists?(filename) ? Environment.new(filename).apply : {})
    end
  end

  # same as `load`, but raises Errno::ENOENT if any files don't exist
  def self.load!(*filenames)
    load(
      *default_if_empty(filenames).each do |filename|
        filename = File.expand_path filename
        raise(Errno::ENOENT.new(filename)) unless File.exists?(filename)
      end
    )
  end

protected
  def self.default_if_empty(filenames)
    filenames.empty? ? (filenames << '.env') : filenames
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/dotenv-0.9.0/lib/dotenv.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/dotenv-0.9.0/lib/dotenv.rb
mango-0.7.0 vendor/bundler/ruby/2.0.0/gems/dotenv-0.9.0/lib/dotenv.rb
dotenv-0.9.0 lib/dotenv.rb
dotenv-0.8.0 lib/dotenv.rb