Sha256: 2f115fe4ffec1197200117692ae73b3fad0f6ee42ea36c9e81a20b7c7d4cb50b
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module Bundler class EnvironmentPreserver INTENTIONALLY_NIL = "BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL".freeze BUNDLER_KEYS = %w[ BUNDLE_BIN_PATH BUNDLE_GEMFILE BUNDLER_ORIG_MANPATH BUNDLER_VERSION GEM_HOME GEM_PATH MANPATH PATH RUBYLIB RUBYOPT ].map(&:freeze).freeze BUNDLER_PREFIX = "BUNDLER_ORIG_".freeze # @param env [ENV] # @param keys [Array<String>] def initialize(env, keys) @original = env.to_hash @keys = keys @prefix = BUNDLER_PREFIX end # @return [Hash] def backup env = @original.clone @keys.each do |key| value = env[key] if !value.nil? && !value.empty? env[@prefix + key] ||= value elsif value.nil? env[@prefix + key] ||= INTENTIONALLY_NIL end end env end # @return [Hash] def restore env = @original.clone @keys.each do |key| value_original = env[@prefix + key] next if value_original.nil? || value_original.empty? if value_original == INTENTIONALLY_NIL env.delete(key) else env[key] = value_original end env.delete(@prefix + key) end env end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bundler-1.16.0.pre.2 | lib/bundler/environment_preserver.rb |
bundler-1.16.0.pre.1 | lib/bundler/environment_preserver.rb |