diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-08-25 15:34:09 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-08-26 15:00:46 -0500 |
commit | 3b6dd372dca9b695e9283d8c49644b9dec9ef260 (patch) | |
tree | e4d2858bc47cef1fada0800f3c271a79e8cb8228 | |
parent | c71f43fbcb9ee25bc4466137cc29545cda1375e2 (diff) | |
download | bundler-3b6dd372dca9b695e9283d8c49644b9dec9ef260.tar.gz |
[Settings] Allow temporarily overriding settings in-memoryseg-settings-temporary
-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) |