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 BUNDLER_SETUP GEM_HOME GEM_PATH MANPATH PATH RB_USER_INSTALL RUBYLIB RUBYOPT ].map(&:freeze).freeze
-
BUNDLER_PREFIX =
# File 'lib/bundler/environment_preserver.rb', line 19"BUNDLER_ORIG_"
-
INTENTIONALLY_NIL =
# File 'lib/bundler/environment_preserver.rb', line 5"BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL"
Class Method Summary
- .from_env
- .new(env, keys) ⇒ EnvironmentPreserver constructor
Instance Method Summary
- #backup ⇒ Hash
-
#replace_with_backup
Replaces
ENV
with the bundler environment variables backed up. - #restore ⇒ Hash
Constructor Details
.new(env, keys) ⇒ EnvironmentPreserver
# File 'lib/bundler/environment_preserver.rb', line 27
def initialize(env, keys) @original = env @keys = keys @prefix = BUNDLER_PREFIX end
Class Method Details
.from_env
[ GitHub ]# File 'lib/bundler/environment_preserver.rb', line 21
def self.from_env new(ENV.to_hash, BUNDLER_KEYS) end
Instance Method Details
#backup ⇒ Hash
# File 'lib/bundler/environment_preserver.rb', line 39
def backup env = @original.clone @keys.each do |key| value = env[key] if !value.nil? env[@prefix + key] ||= value else env[@prefix + key] ||= INTENTIONALLY_NIL end end env end
#replace_with_backup
Replaces ENV
with the bundler environment variables backed up
# File 'lib/bundler/environment_preserver.rb', line 34
def replace_with_backup ENV.replace(backup) end
#restore ⇒ Hash
# File 'lib/bundler/environment_preserver.rb', line 53
def restore env = @original.clone @keys.each do |key| value_original = env[@prefix + key] next if value_original.nil? if value_original == INTENTIONALLY_NIL env.delete(key) else env[key] = value_original end env.delete(@prefix + key) end env end