Sha256: a1e2acddc4825a08727a02d2fe81f5556500be88bbf6526c49f46373f92339bd

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'dotenv'

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

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

  def load!
    vars = ::Dotenv.load(*dotenv_files)
    Ssm.new(vars).interpolate!
  end

  # dotenv files with the following precedence:
  #
  # - .env.development.jets_env_extra (highest)
  # - .env.development.remote (2nd 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
    if ENV["JETS_ENV_EXTRA"]
      files << root.join(".env.#{Jets.env}.#{ENV["JETS_ENV_EXTRA"]}")
    end
    files.compact
  end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jets-1.9.19 lib/jets/dotenv.rb