Sha256: e41e4671d537066fb129318fc6c8dcf7d664db8999606b865008825d7746ce86

Contents?: true

Size: 868 Bytes

Versions: 35

Compression:

Stored size: 868 Bytes

Contents

# frozen_string_literal: true
module Bundler
  class EnvironmentPreserver
    # @param env [ENV]
    # @param keys [Array<String>]
    def initialize(env, keys)
      @original = env.to_hash
      @keys = keys
      @prefix = "BUNDLER_ORIG_"
    end

    # @return [Hash]
    def backup
      env = @original.clone
      @keys.each do |key|
        value = env[key]
        original_value = env[@prefix + key]
        if !value.nil? && !value.empty? && original_value.nil?
          env[@prefix + key] = value
        end
      end
      env
    end

    # @return [Hash]
    def restore
      env = @original.clone
      @keys.each do |key|
        value_original = env[@prefix + key]
        unless value_original.nil? || value_original.empty?
          env[key] = value_original
          env.delete(@prefix + key)
        end
      end
      env
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
rubygems-update-2.6.14 bundler/lib/bundler/environment_preserver.rb
rubygems-update-2.6.13 bundler/lib/bundler/environment_preserver.rb
bundler-1.15.4 lib/bundler/environment_preserver.rb
bundler-1.15.3 lib/bundler/environment_preserver.rb
bundler-1.15.2 lib/bundler/environment_preserver.rb
bundler-1.15.1 lib/bundler/environment_preserver.rb
bundler-1.15.0 lib/bundler/environment_preserver.rb
bundler-1.15.0.pre.4 lib/bundler/environment_preserver.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/bundler-1.14.6/lib/bundler/environment_preserver.rb
bundler-1.15.0.pre.3 lib/bundler/environment_preserver.rb
rubygems-update-2.6.12 bundler/lib/bundler/environment_preserver.rb
bundler-1.15.0.pre.2 lib/bundler/environment_preserver.rb
bundler-1.15.0.pre.1 lib/bundler/environment_preserver.rb
rubygems-update-2.6.11 bundler/lib/bundler/environment_preserver.rb
bundler-1.14.6 lib/bundler/environment_preserver.rb
bundler-1.14.5 lib/bundler/environment_preserver.rb
bundler-1.14.4 lib/bundler/environment_preserver.rb
bundler-1.14.3 lib/bundler/environment_preserver.rb
rubygems-update-2.6.10 bundler/lib/bundler/environment_preserver.rb
bundler-1.14.2 lib/bundler/environment_preserver.rb