Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

support setting boolean environment variables #2144

Merged
merged 1 commit into from

2 participants

@brettporter

These were previously stored as a string if they are derived from the
environment or configuration files. Rather than altering each of the checks,
we can select a list of settings to convert to boolean values when they are
accessed.

I bumped into this specific problem trying to override bundle config --global frozen true with a BUNDLE_FROZEN=false environment variable.

@brettporter brettporter support setting boolean environment variables
These were previously stored as a string if they are derived from the
environment or configuration files. Rather than altering each of the checks,
we can select a list of settings to convert to boolean values when they are
accessed.
b4101be
@indirect
Owner

Seems legit. Thanks!

@indirect indirect merged commit b4101be into bundler:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 2, 2012
  1. @brettporter

    support setting boolean environment variables

    brettporter authored
    These were previously stored as a string if they are derived from the
    environment or configuration files. Rather than altering each of the checks,
    we can select a list of settings to convert to boolean values when they are
    accessed.
This page is out of date. Refresh to see the latest.
View
13 lib/bundler/settings.rb
@@ -7,8 +7,9 @@ def initialize(root)
end
def [](key)
- key = key_for(key)
- @local_config[key] || ENV[key] || @global_config[key]
+ the_key = key_for(key)
+ value = (@local_config[the_key] || ENV[the_key] || @global_config[the_key])
+ is_bool(key) ? to_bool(value) : value
end
def []=(key, value)
@@ -104,6 +105,14 @@ def key_for(key)
"BUNDLE_#{key}"
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)
key = key_for(key)
View
14 spec/install/deploy_spec.rb
@@ -113,6 +113,20 @@
expect(out).not_to include("You have changed in the Gemfile")
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
gemfile <<-G
source "file://#{gem_repo1}"
View
31 spec/other/config_spec.rb
@@ -135,4 +135,35 @@
expect(out).to eq("local")
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
Something went wrong with that request. Please try again.