summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-06-22 17:35:07 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-06-23 18:41:36 -0500
commit3821b16cd72d634032aa5526f5aaa2e5858193fc (patch)
tree01b8817eb8167d0f2a8e04d16a9c80a7fd46b164
parent6ea13f5f956c474e48af1acdc65d571d9d55c592 (diff)
downloadbundler-3821b16cd72d634032aa5526f5aaa2e5858193fc.tar.gz
Add machinery for printing major deprecations
-rw-r--r--lib/bundler.rb2
-rw-r--r--lib/bundler/cli.rb2
-rw-r--r--lib/bundler/deprecate.rb16
-rw-r--r--lib/bundler/shared_helpers.rb15
-rw-r--r--lib/bundler/ui/shell.rb19
5 files changed, 44 insertions, 10 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index e8c14be9bd..9da798e2bf 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -92,6 +92,8 @@ module Bundler
definition.validate_ruby!
+ SharedHelpers.print_major_deprecations!
+
if groups.empty?
# Load all groups, but only once
@setup = load.setup
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index c3a9a01e2b..1fb4b1bd41 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -12,6 +12,8 @@ module Bundler
rescue Exception => e
Bundler.ui = UI::Shell.new
raise e
+ ensure
+ Bundler::SharedHelpers.print_major_deprecations!
end
def initialize(*args)
diff --git a/lib/bundler/deprecate.rb b/lib/bundler/deprecate.rb
index 1ab4de1a28..b978c0df6c 100644
--- a/lib/bundler/deprecate.rb
+++ b/lib/bundler/deprecate.rb
@@ -10,7 +10,23 @@ module Bundler
unless Deprecate.respond_to?(:skip_during)
def Deprecate.skip_during
+ original = skip
+ self.skip = true
yield
+ ensure
+ self.skip = original
+ end
+ end
+
+ unless Deprecate.respond_to?(:skip)
+ def Deprecate.skip
+ @skip
+ end
+ end
+
+ unless Deprecate.respond_to?(:skip=)
+ def Deprecate.skip=(skip)
+ @skip = skip
end
end
end
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 01f1118d7b..376235abfd 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -120,6 +120,13 @@ module Bundler
namespace.const_get(constant_name)
end
+ def major_deprecation(message)
+ return unless prints_major_deprecations?
+ @major_deprecation_ui ||= Bundler::UI::Shell.new("no-color" => true)
+ ui = Bundler.ui.is_a?(@major_deprecation_ui.class) ? Bundler.ui : @major_deprecation_ui
+ ui.warn("[DEPRECATED FOR #{Bundler::VERSION.split(".").first.to_i + 1}.0] #{message}")
+ end
+
private
def find_gemfile
@@ -207,6 +214,14 @@ module Bundler
end
end
+ def prints_major_deprecations?
+ require "bundler"
+ return false unless Bundler.settings[:major_deprecations]
+ require "bundler/deprecate"
+ return false if Bundler::Deprecate.skip
+ true
+ end
+
extend self
end
end
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 4422b93065..f940330fb6 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -79,17 +79,8 @@ module Bundler
tell_me(msg, nil, newline)
end
- def major_deprecation(message)
- return unless Bundler.settings[:major_deprecations]
- warn(message)
- end
-
def silence
- old_level = @level
- @level = "silent"
- yield
- ensure
- @level = old_level
+ with_level("silent")
end
private
@@ -114,6 +105,14 @@ module Bundler
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
+
+ def with_level(level)
+ original = @level
+ @level = level
+ yield
+ ensure
+ @level = original
+ end
end
end
end