On Wed, 29 Aug 2007, I wrote:

> Thanks.  I managed to miss that.
> 
> :r! gem help source | grep cache | wc
>        0       0       0
> 
> no mention of the cache in there.  I'll try to work up a doc patch
> 
>         Hugh

I've come up with this so far. Not as nice as I'd like, the duplication
in the second part is basically vile, maybe remove_cache could be a 
protected method of command?  Well, that isn't beautiful either, is it?
Command then knows too much about Source.  Oh well, I'm sure someone 
here can come up with something better.  This is untested as yet, by the
way, so beware.  A patch against the unpacked tar ball grabbed from 
Rubyforge.
        Hugh

:r! (cd /scratch/hgs; display_diffs.rb rubygems-0.9.4)

--- rubygems-0.9.4/lib/rubygems/commands/sources_command.rb.orig        
2007-05-23 15:51:31.000000000 +0100
+++ rubygems-0.9.4/lib/rubygems/commands/sources_command.rb     2007-08-29 
18:15:20.674031000 +0100
@@ -18,7 +18,7 @@
           options[:remove] = value
         end
 
-        add_option '-c', '--clear-all', 'Remove all sources' do |value, 
options|
+        add_option '-c', '--clear-all', 'Remove all sources (clear the cache)' 
do |value, options|
           options[:clear_all] = value
         end
       end
--- rubygems-0.9.4/lib/rubygems/commands/clear_cache_command.rb.orig    
2007-08-29 18:22:58.049867000 +0100
+++ rubygems-0.9.4/lib/rubygems/commands/clear_cache_command.rb 2007-08-29 
18:29:57.586782000 +0100
@@ -0,0 +1,37 @@
+module Gem
+  module Commands
+  
+    class Clear_cacheCommand < Command
+
+      def initialize
+        super 'clear_cache', 'clear the sources i.e the cache.'
+
+      end
+
+      def defaults_str
+        ''
+      end
+
+      def execute
+        remove_cache_file("user", Gem::SourceInfoCache.user_cache_file)
+        remove_cache_file("system", Gem::SourceInfoCache.system_cache_file)
+        say "Cache cleared"
+
+      end
+
+      def remove_cache_file(desc, fn)
+        FileUtils.rm_rf fn rescue nil
+        if ! File.exist?(fn)
+          say "*** Removed #{desc} source cache ***"
+        elsif ! File.writable?(fn)
+          say "*** Unable to remove #{desc} source cache (write protected) ***"
+        else
+          say "*** Unable to remove #{desc} source cache ***"
+        end
+      end
+      private :remove_cache_file
+      # It's private, so we need our own copy. Very non-DRY.
+
+    end # class Clear_cacheCommand
+  end # module Commands
+end # module Gem
_______________________________________________
Rubygems-developers mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rubygems-developers

Reply via email to