Class: Bundler::EnvironmentPreserver
- Inherits:
-
Object
- Object
- Bundler::EnvironmentPreserver
- Defined in:
- lib/bundler/environment_preserver.rb
Constant Summary collapse
- INTENTIONALLY_NIL =
"BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL"- BUNDLER_KEYS =
%w[ BUNDLE_BIN_PATH BUNDLE_GEMFILE BUNDLE_LOCKFILE BUNDLER_VERSION BUNDLER_SETUP GEM_HOME GEM_PATH MANPATH PATH RB_USER_INSTALL RUBYLIB RUBYOPT ].map(&:freeze).freeze
- BUNDLER_PREFIX =
"BUNDLER_ORIG_"
Class Method Summary collapse
Instance Method Summary collapse
- #backup ⇒ Hash
-
#initialize(env, keys) ⇒ EnvironmentPreserver
constructor
A new instance of EnvironmentPreserver.
-
#replace_with_backup ⇒ Object
Replaces ‘ENV` with the bundler environment variables backed up.
- #restore ⇒ Hash
Constructor Details
#initialize(env, keys) ⇒ EnvironmentPreserver
Returns a new instance of EnvironmentPreserver.
28 29 30 31 32 |
# File 'lib/bundler/environment_preserver.rb', line 28 def initialize(env, keys) @original = env @keys = keys @prefix = BUNDLER_PREFIX end |
Class Method Details
.from_env ⇒ Object
22 23 24 |
# File 'lib/bundler/environment_preserver.rb', line 22 def self.from_env new(ENV.to_hash, BUNDLER_KEYS) end |
Instance Method Details
#backup ⇒ Hash
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/bundler/environment_preserver.rb', line 40 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 ⇒ Object
Replaces ‘ENV` with the bundler environment variables backed up
35 36 37 |
# File 'lib/bundler/environment_preserver.rb', line 35 def replace_with_backup ENV.replace(backup) end |
#restore ⇒ Hash
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bundler/environment_preserver.rb', line 54 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 |