121925
From 75821c744f0bfda185eac35b91810254bf9e2367 Mon Sep 17 00:00:00 2001
121925
From: Aaron Patterson <aaron.patterson@gmail.com>
121925
Date: Wed, 5 Feb 2014 16:42:04 -0800
121925
Subject: [PATCH] refactor checking `really_verbose`
121925
121925
This commit tries to reduce the number of places in RubyGems where we
121925
test `really_verbose`.
121925
---
121925
 lib/rubygems/commands/cleanup_command.rb |  4 ++--
121925
 lib/rubygems/dependency_installer.rb     |  6 +++---
121925
 lib/rubygems/installer.rb                |  6 +++---
121925
 lib/rubygems/package.rb                  |  2 +-
121925
 lib/rubygems/package/old.rb              |  2 +-
121925
 lib/rubygems/rdoc.rb                     |  2 +-
121925
 lib/rubygems/remote_fetcher.rb           | 23 ++++++++---------------
121925
 lib/rubygems/user_interaction.rb         |  8 ++++++++
121925
 8 files changed, 27 insertions(+), 26 deletions(-)
121925
121925
diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb
121925
index c8f0082bfb..69975640fe 100644
121925
--- a/lib/rubygems/commands/cleanup_command.rb
121925
+++ b/lib/rubygems/commands/cleanup_command.rb
121925
@@ -66,10 +66,10 @@ def execute
121925
 
121925
     say "Clean Up Complete"
121925
 
121925
-    if Gem.configuration.really_verbose then
121925
+    verbose do
121925
       skipped = @default_gems.map { |spec| spec.full_name }
121925
 
121925
-      say "Skipped default gems: #{skipped.join ', '}"
121925
+      "Skipped default gems: #{skipped.join ', '}"
121925
     end
121925
   end
121925
 
121925
diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb
121925
index 5644b5ce73..4ea3847b70 100644
121925
--- a/lib/rubygems/dependency_installer.rb
121925
+++ b/lib/rubygems/dependency_installer.rb
121925
@@ -165,9 +165,9 @@ def find_gems_with_sources dep, best_only=false # :nodoc:
121925
         # FIX if there is a problem talking to the network, we either need to always tell
121925
         # the user (no really_verbose) or fail hard, not silently tell them that we just
121925
         # couldn't find their requested gem.
121925
-        if Gem.configuration.really_verbose then
121925
-          say "Error fetching remote data:\t\t#{e.message}"
121925
-          say "Falling back to local-only install"
121925
+        verbose do
121925
+          "Error fetching remote data:\t\t#{e.message}\n" \
121925
+            "Falling back to local-only install"
121925
         end
121925
         @domain = :local
121925
       end
121925
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
121925
index cbae8234a1..548f1262a8 100644
121925
--- a/lib/rubygems/installer.rb
121925
+++ b/lib/rubygems/installer.rb
121925
@@ -357,7 +357,7 @@ def generate_windows_script(filename, bindir)
121925
         file.puts windows_stub_script(bindir, filename)
121925
       end
121925
 
121925
-      say script_path if Gem.configuration.really_verbose
121925
+      verbose script_path
121925
     end
121925
   end
121925
 
121925
@@ -408,7 +408,7 @@ def generate_bin_script(filename, bindir)
121925
       file.print app_script_text(filename)
121925
     end
121925
 
121925
-    say bin_script_path if Gem.configuration.really_verbose
121925
+    verbose bin_script_path
121925
 
121925
     generate_windows_script filename, bindir
121925
   end
121925
@@ -694,7 +694,7 @@ def build_extension extension, dest_path # :nodoc:
121925
             results = builder.build(extension, gem_dir, dest_path,
121925
                                     results, @build_args)
121925
 
121925
-            say results.join("\n") if Gem.configuration.really_verbose
121925
+            verbose { results.join("\n") }
121925
           end
121925
         end
121925
       rescue
121925
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
121925
index ae20f22b94..417b34b79f 100644
121925
--- a/lib/rubygems/package.rb
121925
+++ b/lib/rubygems/package.rb
121925
@@ -347,7 +347,7 @@ def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:
121925
           out.write entry.read
121925
         end
121925
 
121925
-        say destination if Gem.configuration.really_verbose
121925
+        verbose destination
121925
       end
121925
     end
121925
   end
121925
diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb
121925
index 30c30c0201..c47210d2a0 100644
121925
--- a/lib/rubygems/package/old.rb
121925
+++ b/lib/rubygems/package/old.rb
121925
@@ -83,7 +83,7 @@ def extract_files destination_dir
121925
           out.write file_data
121925
         end
121925
 
121925
-        say destination if Gem.configuration.really_verbose
121925
+        verbose destination
121925
       end
121925
     end
121925
   rescue Zlib::DataError
121925
diff --git a/lib/rubygems/rdoc.rb b/lib/rubygems/rdoc.rb
121925
index 633bd893a5..394e502051 100644
121925
--- a/lib/rubygems/rdoc.rb
121925
+++ b/lib/rubygems/rdoc.rb
121925
@@ -263,7 +263,7 @@ def legacy_rdoc *args
121925
       Gem::Requirement.new('>= 2.4.0') =~ self.class.rdoc_version
121925
 
121925
     r = new_rdoc
121925
-    say "rdoc #{args.join ' '}" if Gem.configuration.really_verbose
121925
+    verbose { "rdoc #{args.join ' '}" }
121925
 
121925
     Dir.chdir @spec.full_gem_path do
121925
       begin
121925
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
121925
index 2490c69556..9df48bf6f3 100644
121925
--- a/lib/rubygems/remote_fetcher.rb
121925
+++ b/lib/rubygems/remote_fetcher.rb
121925
@@ -168,8 +168,7 @@ def download(spec, source_uri, install_dir = Gem.dir)
121925
     when 'http', 'https' then
121925
       unless File.exist? local_gem_path then
121925
         begin
121925
-          say "Downloading gem #{gem_file_name}" if
121925
-            Gem.configuration.really_verbose
121925
+          verbose "Downloading gem #{gem_file_name}"
121925
 
121925
           remote_gem_path = source_uri + "gems/#{gem_file_name}"
121925
 
121925
@@ -179,8 +178,7 @@ def download(spec, source_uri, install_dir = Gem.dir)
121925
 
121925
           alternate_name = "#{spec.original_name}.gem"
121925
 
121925
-          say "Failed, downloading gem #{alternate_name}" if
121925
-            Gem.configuration.really_verbose
121925
+          verbose "Failed, downloading gem #{alternate_name}"
121925
 
121925
           remote_gem_path = source_uri + "gems/#{alternate_name}"
121925
 
121925
@@ -199,8 +197,7 @@ def download(spec, source_uri, install_dir = Gem.dir)
121925
         local_gem_path = source_uri.to_s
121925
       end
121925
 
121925
-      say "Using local gem #{local_gem_path}" if
121925
-        Gem.configuration.really_verbose
121925
+      verbose "Using local gem #{local_gem_path}"
121925
     when nil then # TODO test for local overriding cache
121925
       source_path = if Gem.win_platform? && source_uri.scheme &&
121925
                        !source_uri.path.include?(':') then
121925
@@ -218,8 +215,7 @@ def download(spec, source_uri, install_dir = Gem.dir)
121925
         local_gem_path = source_uri.to_s
121925
       end
121925
 
121925
-      say "Using local gem #{local_gem_path}" if
121925
-        Gem.configuration.really_verbose
121925
+      verbose "Using local gem #{local_gem_path}"
121925
     else
121925
       raise ArgumentError, "unsupported URI scheme #{source_uri.scheme}"
121925
     end
121925
@@ -506,8 +502,7 @@ def fetch
121925
     begin
121925
       @requests[connection.object_id] += 1
121925
 
121925
-      say "#{request.method} #{uri}" if
121925
-        Gem.configuration.really_verbose
121925
+      verbose "#{request.method} #{uri}"
121925
 
121925
       file_name = File.basename(uri.path)
121925
       # perform download progress reporter only for gems
121925
@@ -536,11 +531,10 @@ def fetch
121925
         response = connection.request request
121925
       end
121925
 
121925
-      say "#{response.code} #{response.message}" if
121925
-        Gem.configuration.really_verbose
121925
+      verbose "#{response.code} #{response.message}"
121925
 
121925
     rescue Net::HTTPBadResponse
121925
-      say "bad response" if Gem.configuration.really_verbose
121925
+      verbose "bad response"
121925
 
121925
       reset connection
121925
 
121925
@@ -555,8 +549,7 @@ def fetch
121925
            Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
121925
 
121925
       requests = @requests[connection.object_id]
121925
-      say "connection reset after #{requests} requests, retrying" if
121925
-        Gem.configuration.really_verbose
121925
+      verbose "connection reset after #{requests} requests, retrying"
121925
 
121925
       raise FetchError.new('too many connection resets', uri) if retried
121925
 
121925
diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb
121925
index f5e460f994..42ab6e2c24 100644
121925
--- a/lib/rubygems/user_interaction.rb
121925
+++ b/lib/rubygems/user_interaction.rb
121925
@@ -119,6 +119,14 @@ def say statement = ''
121925
   def terminate_interaction(*args)
121925
     ui.terminate_interaction(*args)
121925
   end
121925
+
121925
+  ##
121925
+  # Calls +say+ with +msg+ or the results of the block if really_verbose
121925
+  # is true.
121925
+
121925
+  def verbose msg = nil
121925
+    say(msg || yield) if Gem.configuration.really_verbose
121925
+  end
121925
 end
121925
 
121925
 ##