Sha256: 6ad6c1c9bbccea74c11672e83a474a4f057e375ae5d0e9397b99f1d7ddb8b719

Contents?: true

Size: 1.67 KB

Versions: 18

Compression:

Stored size: 1.67 KB

Contents

module Pantograph
  module Helper
    class DotenvHelper
      # @param env_cl_param [String] an optional list of dotenv environment names separated by commas, without space
      def self.load_dot_env(env_cl_param)
        base_path = find_dotenv_directory

        return unless base_path

        load_dot_envs_from(env_cl_param, base_path)
      end

      # finds the first directory of [pantograph, its parent] containing dotenv files
      def self.find_dotenv_directory
        path = PantographCore::PantographFolder.path
        search_paths = [path]
        search_paths << path + "/.." unless path.nil?
        search_paths.compact!
        search_paths.find do |dir|
          Dir.glob(File.join(dir, '*.env*'), File::FNM_DOTMATCH).count > 0
        end
      end

      # loads the dotenvs. First the .env and .env.default and
      # then override with all speficied extra environments
      def self.load_dot_envs_from(env_cl_param, base_path)
        require 'dotenv'

        # Making sure the default '.env' and '.env.default' get loaded
        env_file = File.join(base_path, '.env')
        env_default_file = File.join(base_path, '.env.default')
        Dotenv.load(env_file, env_default_file)

        return unless env_cl_param

        Pantograph::Actions.lane_context[Pantograph::Actions::SharedValues::ENVIRONMENT] = env_cl_param

        # multiple envs?
        envs = env_cl_param.split(",")

        # Loads .env file for the environment(s) passed in through options
        envs.each do |env|
          env_file = File.join(base_path, ".env.#{env}")
          UI.success("Loading from '#{env_file}'")
          Dotenv.overload(env_file)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pantograph-0.1.22 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.21 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.20 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.19 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.17 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.16 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.15 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.14 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.13 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.12 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.10 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.8 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.7 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.6 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.4 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.3 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.1 pantograph/lib/pantograph/helper/dotenv_helper.rb
pantograph-0.1.0 pantograph/lib/pantograph/helper/dotenv_helper.rb