Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

support setting boolean environment variables #2144

Merged
merged 1 commit into from Feb 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/bundler/settings.rb
Expand Up @@ -7,8 +7,9 @@ def initialize(root)
end end


def [](key) def [](key)
key = key_for(key) the_key = key_for(key)
@local_config[key] || ENV[key] || @global_config[key] value = (@local_config[the_key] || ENV[the_key] || @global_config[the_key])
is_bool(key) ? to_bool(value) : value
end end


def []=(key, value) def []=(key, value)
Expand Down Expand Up @@ -104,6 +105,14 @@ def key_for(key)
"BUNDLE_#{key}" "BUNDLE_#{key}"
end end


def is_bool(key)
%w(frozen cache_all no_prune disable_local_branch_check).include? key.to_s
end

def to_bool(value)
!(value.nil? || value == '' || value =~ /^(false|f|no|n|0)$/i)
end

def set_key(key, value, hash, file) def set_key(key, value, hash, file)
key = key_for(key) key = key_for(key)


Expand Down
14 changes: 14 additions & 0 deletions spec/install/deploy_spec.rb
Expand Up @@ -113,6 +113,20 @@
expect(out).not_to include("You have changed in the Gemfile") expect(out).not_to include("You have changed in the Gemfile")
end end


it "can have --frozen set to false via an environment variable" do
gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
gem "rack-obama"
G

ENV['BUNDLE_FROZEN'] = "false"
bundle "install"
expect(out).not_to include("deployment mode")
expect(out).not_to include("You have added to the Gemfile")
expect(out).not_to include("* rack-obama")
end

it "explodes with the --frozen flag if you make a change and don't check in the lockfile" do it "explodes with the --frozen flag if you make a change and don't check in the lockfile" do
gemfile <<-G gemfile <<-G
source "file://#{gem_repo1}" source "file://#{gem_repo1}"
Expand Down
31 changes: 31 additions & 0 deletions spec/other/config_spec.rb
Expand Up @@ -135,4 +135,35 @@
expect(out).to eq("local") expect(out).to eq("local")
end end
end end

describe "env" do
before(:each) { bundle :install }

it "can set boolean properties via the environment" do
ENV["BUNDLE_FROZEN"] = "true"

run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end"
expect(out).to eq("true")
end

it "can set negative boolean properties via the environment" do
run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end"
expect(out).to eq("false")

ENV["BUNDLE_FROZEN"] = "false"

run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end"
expect(out).to eq("false")

ENV["BUNDLE_FROZEN"] = "0"

run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end"
expect(out).to eq("false")

ENV["BUNDLE_FROZEN"] = ""

run "if Bundler.settings[:frozen]; puts 'true' else puts 'false' end"
expect(out).to eq("false")
end
end
end end