diff options
author | Homu <homu@barosl.com> | 2016-08-30 08:15:21 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-08-30 08:15:21 +0900 |
commit | 138dde753d731020122827b511d314230104cfe8 (patch) | |
tree | fb3114cb8ed975a97f3c77a09f638204579f8e71 | |
parent | 2b4b82611b1d1408a9e1cefafec9308d52b0a4f4 (diff) | |
parent | 3b6dd372dca9b695e9283d8c49644b9dec9ef260 (diff) | |
download | bundler-138dde753d731020122827b511d314230104cfe8.tar.gz |
Auto merge of #4917 - bundler:seg-settings-temporary, r=indirect
[Settings] Allow temporarily overriding settings in-memory
-rw-r--r-- | lib/bundler/cli.rb | 8 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 20 |
2 files changed, 22 insertions, 6 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index e729cd3bb2..8b48be35d2 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -184,11 +184,9 @@ module Bundler map "i" => "install" def install require "bundler/cli/install" - no_install = Bundler.settings[:no_install] - Bundler.settings[:no_install] = false if no_install == true - Install.new(options.dup).run - ensure - Bundler.settings[:no_install] = no_install unless no_install.nil? + Bundler.settings.temporary(:no_install => false) do + Install.new(options.dup).run + end end desc "update [OPTIONS]", "update the current environment" diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index c5fd46d440..4d1271df65 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -42,11 +42,18 @@ module Bundler @local_config = load_config(local_config_file) @global_config = load_config(global_config_file) @cli_flags_given = false + @temporary = {} end def [](name) key = key_for(name) - value = (@local_config[key] || ENV[key] || @global_config[key] || DEFAULT_CONFIG[name]) + value = @temporary.fetch(name) do + @local_config.fetch(key) do + ENV.fetch(key) do + @global_config.fetch(key) do + DEFAULT_CONFIG.fetch(name) do + nil + end end end end end if value.nil? nil @@ -77,6 +84,17 @@ module Bundler set_key(key, value, @local_config, local_config_file) end + def temporary(update) + existing = Hash[update.map {|k, _| [k, @temporary[k]] }] + @temporary.update(update) + return unless block_given? + begin + yield + ensure + existing.each {|k, v| v.nil? ? @temporary.delete(k) : @temporary[k] = v } + end + end + alias_method :set_local, :[]= def delete(key) |