Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added 'minigem rever GEM_NAME' command to revert back to rubygems

  • Loading branch information...
commit 2304761c39e68352b0beb1dd57c53b546d3588c3 1 parent 267893f
Fabien Franzen authored September 16, 2008
4  README
@@ -21,6 +21,10 @@ to use minigems:
21 21
 
22 22
 sudo minigem prepare merb-core
23 23
 
  24
+And to revert back to rubygems:
  25
+
  26
+sudo minigem revert merb-core
  27
+
24 28
 To use minigems in your own scripts, use the following construct, instead of the 
25 29
 common 'require "rubygems"' statement:
26 30
 
9  bin/minigem
@@ -11,6 +11,7 @@ if ARGV.empty? || %w[-H --help].detect { |o| ARGV.index(o) }
11 11
   puts "  #{program} setup"
12 12
   puts "  #{program} remove"
13 13
   puts "  #{program} prepare GEMNAME [GEMNAME ...]"
  14
+  puts "  #{program} revert  GEMNAME [GEMNAME ...]"
14 15
   puts "  #{program} install GEMNAME [GEMNAME ...] [options] -- --build-flags [options]"
15 16
   puts "  #{program} update  GEMNAME [GEMNAME ...] [options]"
16 17
   puts "  #{program} <command> GEMNAME [GEMNAME ...] [options]"
@@ -61,6 +62,14 @@ elsif ARGV[0] == 'prepare'
61 62
     next unless (gem_spec = Gem.source_index.find_name(gem_name).sort_by { |g| g.version }.last)
62 63
     adapt_executables_for(gem_spec)
63 64
   end
  65
+elsif ARGV[0] == 'revert'
  66
+  # Adapt a gems' executable wrapper to use rubygems.
  67
+  ARGV.shift # skip prepare command argument
  68
+  ensure_in_load_path!(ARGV.empty?)
  69
+  ARGV.each do |gem_name|
  70
+    next unless (gem_spec = Gem.source_index.find_name(gem_name).sort_by { |g| g.version }.last)
  71
+    revert_executables_for(gem_spec)
  72
+  end
64 73
 elsif ARGV[0] == 'install' || ARGV[0] == 'update'
65 74
   # Install or update a rubygem and prepare it for minigems.
66 75
   command = ARGV.shift.to_sym # skip command argument
2  lib/minigems/executable_wrapper
@@ -5,7 +5,7 @@ SHEBANG
5 5
 # The application 'EXECUTABLE_NAME' is installed as part of a gem (GEM_NAME),
6 6
 # and this file is here to facilitate running it.
7 7
 
8  
-require 'minigems'
  8
+require 'GEM_MODE'
9 9
 
10 10
 version = ">= 0"
11 11
 
33  lib/minigems/script_helper.rb
@@ -60,14 +60,36 @@ def adapt_executables_for(gemspec)
60 60
           next if executable == 'minigem' # better not modify minigem itself
61 61
           if File.exists?(wrapper_path = File.join(Gem.bindir, executable))
62 62
             wrapper_code = interpolate_wrapper(gemspec.name, executable)
63  
-            if File.open(wrapper_path, 'w') { |f| f.write(wrapper_code) }
64  
-              puts "Adapted #{wrapper_path} to use minigems instead of rubygems."
65  
-            else
  63
+            begin
  64
+              if File.open(wrapper_path, 'w') { |f| f.write(wrapper_code) }
  65
+                puts "Adapted #{wrapper_path} to use minigems instead of rubygems."
  66
+              else
  67
+                puts "Failed to adapt #{wrapper_path} - maybe you need sudo permissions?"
  68
+              end
  69
+            rescue Errno::EACCES => e
66 70
               puts "Failed to adapt #{wrapper_path} - maybe you need sudo permissions?"
67  
-            end
  71
+            end  
68 72
           end
69 73
         end
70 74
       end
  75
+      
  76
+      def revert_executables_for(gemspec)
  77
+        gemspec.executables.each do |executable|
  78
+          next if executable == 'minigem' # better not modify minigem itself
  79
+          if File.exists?(wrapper_path = File.join(Gem.bindir, executable))
  80
+            wrapper_code = interpolate_wrapper(gemspec.name, executable, 'rubygems')
  81
+            begin
  82
+              if File.open(wrapper_path, 'w') { |f| f.write(wrapper_code) }
  83
+                puts "Reverted #{wrapper_path} to use rubygems instead of minigems."
  84
+              else
  85
+                puts "Failed to revert #{wrapper_path} - maybe you need sudo permissions?"
  86
+              end
  87
+            rescue Errno::EACCES => e
  88
+              puts "Failed to revert #{wrapper_path} - maybe you need sudo permissions?"
  89
+            end
  90
+          end
  91
+        end      
  92
+      end
71 93
 
72 94
       def ensure_in_load_path!(force = false)
73 95
         install_path = File.join(Gem::ConfigMap[:sitelibdir], 'minigems.rb')
@@ -100,10 +122,11 @@ def remove_minigems!
100 122
         end
101 123
       end
102 124
       
103  
-      def interpolate_wrapper(gem_name, executable_name)
  125
+      def interpolate_wrapper(gem_name, executable_name, mode = 'minigems')
104 126
         @template_code ||= File.read(File.join(minigems_path, 'lib', 'minigems', 'executable_wrapper'))
105 127
         vars = { 'GEM_NAME' => gem_name, 'EXECUTABLE_NAME' => executable_name }
106 128
         vars['SHEBANG'] = "#!/usr/bin/env " + Gem::ConfigMap[:ruby_install_name]
  129
+        vars['GEM_MODE'] = mode
107 130
         vars.inject(@template_code) { |str,(k,v)| str.gsub(k,v) }
108 131
       end
109 132
   

0 notes on commit 2304761

Please sign in to comment.
Something went wrong with that request. Please try again.