Sha256: 39832781531c9463198fa7489b6254f53ec5875bd377a6bfd2e91cd3bdea6aad

Contents?: true

Size: 942 Bytes

Versions: 43

Compression:

Stored size: 942 Bytes

Contents

require 'dotenv'

class Jets::Dotenv
  def self.load!(remote=false)
    new(remote).load!
  end

  def initialize(remote=false)
    @remote = remote
    @remote = ENV['JETS_ENV_REMOTE'] if ENV['JETS_ENV_REMOTE']
  end

  def load!
    ::Dotenv.load(*dotenv_files)
  end

  # dotenv files with the following precedence:
  #
  # - .env.development.remote (highest)
  # - .env.development.local
  # - .env.development
  # - .env.local - This file is loaded for all environments _except_ `test`.
  # - .env` - The original (lowest)
  #
  def dotenv_files
    files = [
      root.join(".env"),
      (root.join(".env.local") unless Jets.env.test?),
      root.join(".env.#{Jets.env}"),
      root.join(".env.#{Jets.env}.local"),
    ]
    files << root.join(".env.#{Jets.env}.remote") if @remote
    files.reverse.compact # reverse so the precedence is right
  end

  def root
    Jets.root || Pathname.new(ENV["JETS_ROOT"] || Dir.pwd)
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
jets-1.9.17 lib/jets/dotenv.rb
jets-1.9.16 lib/jets/dotenv.rb
jets-1.9.15 lib/jets/dotenv.rb
jets-1.9.14 lib/jets/dotenv.rb
jets-1.9.13 lib/jets/dotenv.rb
jets-1.9.12 lib/jets/dotenv.rb
jets-1.9.11 lib/jets/dotenv.rb
jets-1.9.10 lib/jets/dotenv.rb
jets-1.9.9 lib/jets/dotenv.rb
jets-1.9.8 lib/jets/dotenv.rb
jets-1.9.7 lib/jets/dotenv.rb
jets-1.9.6 lib/jets/dotenv.rb
jets-1.9.5 lib/jets/dotenv.rb
jets-1.9.4 lib/jets/dotenv.rb
jets-1.9.3 lib/jets/dotenv.rb
jets-1.9.2 lib/jets/dotenv.rb
jets-1.9.1 lib/jets/dotenv.rb
jets-1.9.0 lib/jets/dotenv.rb
jets-1.8.14 lib/jets/dotenv.rb
jets-1.8.13 lib/jets/dotenv.rb