summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-08-18 15:32:12 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-08-18 15:36:36 -0500
commit4a787997c6fb9b520251cd10ce0f2bda4e1c0e64 (patch)
tree48b243e906bb5c4406346f80aec46bf91ae37382
parent54ff7a4fb827ec36d5cac2fac843993f28b19077 (diff)
downloadbundler-seg-feature-flag.tar.gz
Add FeatureFlag classseg-feature-flag
Main use will be code showing what is true setting vs what is flagged Also can be used to develop for future major versions without needing a separate dev branch
-rw-r--r--lib/bundler.rb5
-rw-r--r--lib/bundler/cli.rb4
-rw-r--r--lib/bundler/cli/install.rb2
-rw-r--r--lib/bundler/cli/update.rb2
-rw-r--r--lib/bundler/feature_flag.rb27
-rw-r--r--lib/bundler/fetcher/compact_index.rb2
-rw-r--r--lib/bundler/inline.rb2
-rw-r--r--lib/bundler/plugin.rb2
-rw-r--r--lib/bundler/source/git.rb2
9 files changed, 40 insertions, 8 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 8b3f60d36a..18b9e75253 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -27,6 +27,7 @@ module Bundler
autoload :EndpointSpecification, "bundler/endpoint_specification"
autoload :Env, "bundler/env"
autoload :Fetcher, "bundler/fetcher"
+ autoload :FeatureFlag, "bundler/feature_flag"
autoload :GemHelper, "bundler/gem_helper"
autoload :GemHelpers, "bundler/gem_helpers"
autoload :GemVersionPromoter, "bundler/gem_version_promoter"
@@ -389,6 +390,10 @@ EOF
@git_present = Bundler.which("git") || Bundler.which("git.exe")
end
+ def feature_flag
+ @feature_flag ||= FeatureFlag.new(VERSION)
+ end
+
def reset!
@root = nil
@settings = nil
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 75cceee80d..11edbeb13f 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -92,7 +92,7 @@ module Bundler
end
def self.handle_no_command_error(command, has_namespace = $thor_runner)
- if Bundler.settings[:plugins] && Bundler::Plugin.command?(command)
+ if Bundler.feature_flag.plugins? && Bundler::Plugin.command?(command)
return Bundler::Plugin.exec_command(command, ARGV[1..-1])
end
@@ -491,7 +491,7 @@ module Bundler
Doctor.new(options).run
end
- if Bundler.settings[:plugins]
+ if Bundler.feature_flag.plugins?
require "bundler/cli/plugin"
desc "plugin SUBCOMMAND ...ARGS", "manage the bundler plugins"
subcommand "plugin", Plugin
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index 5c7b8c5b0b..9802ea8036 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -63,7 +63,7 @@ module Bundler
# rubygems plugins sometimes hook into the gem install process
Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins)
- Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.settings[:plugins]
+ Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
definition = Bundler.definition
definition.validate_ruby!
diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb
index 1c35659e0b..c2bf88ff18 100644
--- a/lib/bundler/cli/update.rb
+++ b/lib/bundler/cli/update.rb
@@ -10,7 +10,7 @@ module Bundler
def run
Bundler.ui.level = "error" if options[:quiet]
- Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.settings[:plugins]
+ Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
sources = Array(options[:source])
groups = Array(options[:group]).map(&:to_sym)
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
new file mode 100644
index 0000000000..80bf2a5150
--- /dev/null
+++ b/lib/bundler/feature_flag.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+module Bundler
+ class FeatureFlag
+ def self.settings_flag(flag)
+ unless Bundler::Settings::BOOL_KEYS.include?(flag.to_s)
+ raise "Cannot use `#{flag}` as a settings feature flag since it isn't a bool key"
+ end
+ define_method("#{flag}?") { Bundler.settings[flag] }
+ end
+
+ (1..10).each {|v| define_method("bundler_#{v}_mode?") { major_version >= v } }
+
+ settings_flag :allow_offline_install
+ settings_flag :plugins
+
+ def initialize(bundler_version)
+ @bundler_version = Gem::Version.create(bundler_version)
+ end
+
+ def major_version
+ @bundler_version.segments.first
+ end
+ private :major_version
+
+ class << self; private :settings_flag; end
+ end
+end
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index fb77451822..9461368df5 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -110,7 +110,7 @@ module Bundler
begin
downloader.fetch(fetch_uri + path, headers)
rescue NetworkDownError => e
- raise unless Bundler.settings[:allow_offline_install] && headers["If-None-Match"]
+ raise unless Bundler.feature_flag.allow_offline_install? && headers["If-None-Match"]
Bundler.ui.warn "Using the cached data for the new index because of a network error: #{e}"
Net::HTTPNotModified.new(nil, nil, nil)
end
diff --git a/lib/bundler/inline.rb b/lib/bundler/inline.rb
index dcaf22944c..af542f1e44 100644
--- a/lib/bundler/inline.rb
+++ b/lib/bundler/inline.rb
@@ -41,7 +41,7 @@ def gemfile(install = false, options = {}, &gemfile)
end
ENV["BUNDLE_GEMFILE"] ||= "Gemfile"
- Bundler::Plugin.gemfile_install(&gemfile) if Bundler.settings[:plugins]
+ Bundler::Plugin.gemfile_install(&gemfile) if Bundler.feature_flag.plugins?
builder = Bundler::Dsl.new
builder.instance_eval(&gemfile)
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 1f0297f29b..015be99af8 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -158,7 +158,7 @@ module Bundler
#
# @param [String] event
def hook(event, *args, &arg_blk)
- return unless Bundler.settings[:plugins]
+ return unless Bundler.feature_flag.plugins?
plugins = index.hook_plugins(event)
return unless plugins.any?
diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb
index 60fb555f0a..d1757a4a93 100644
--- a/lib/bundler/source/git.rb
+++ b/lib/bundler/source/git.rb
@@ -292,7 +292,7 @@ module Bundler
def fetch
git_proxy.checkout
rescue GitError
- raise unless Bundler.settings[:allow_offline_install]
+ raise unless Bundler.feature_flag.allow_offline_install?
Bundler.ui.warn "Using cached git data because of network errors"
end
end