Class: Bundler::EnvironmentPreserver
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/bundler/environment_preserver.rb |
Constant Summary
-
BUNDLER_KEYS =
# File 'lib/bundler/environment_preserver.rb', line 6%w[ BUNDLE_BIN_PATH BUNDLE_GEMFILE BUNDLER_VERSION GEM_HOME GEM_PATH MANPATH PATH RB_USER_INSTALL RUBYLIB RUBYOPT ].map(&:freeze).freeze
-
BUNDLER_PREFIX =
# File 'lib/bundler/environment_preserver.rb', line 18"BUNDLER_ORIG_".freeze
-
INTENTIONALLY_NIL =
# File 'lib/bundler/environment_preserver.rb', line 5"BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL".freeze
Class Method Summary
- .new(env, keys) ⇒ EnvironmentPreserver constructor
Instance Method Summary
Constructor Details
.new(env, keys) ⇒ EnvironmentPreserver
# File 'lib/bundler/environment_preserver.rb', line 22
def initialize(env, keys) @original = env.to_hash @keys = keys @prefix = BUNDLER_PREFIX end
Instance Method Details
#backup ⇒ Hash
# File 'lib/bundler/environment_preserver.rb', line 29
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
#restore ⇒ Hash
# File 'lib/bundler/environment_preserver.rb', line 43
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