class Bundler::EnvironmentPreserver
常量
- BUNDLER_KEYS
- BUNDLER_PREFIX
- INTENTIONALLY_NIL
公共类方法
from_env() 点击切换源码
# File bundler/environment_preserver.rb, line 21 def self.from_env new(ENV.to_hash, BUNDLER_KEYS) end
new(env, keys) 点击切换源码
@param env [Hash] @param keys [Array<String>]
# File bundler/environment_preserver.rb, line 27 def initialize(env, keys) @original = env @keys = keys @prefix = BUNDLER_PREFIX end
公共实例方法
backup() 点击切换源码
@return [Hash]
# File 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() 点击切换源码
使用备份的 bundler 环境变量替换 ‘ENV`
# File bundler/environment_preserver.rb, line 34 def replace_with_backup ENV.replace(backup) end
restore() 点击切换源码
@return [Hash]
# File 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