Parent

Included Modules

Class Index [+]

Quicksearch

Gem::Uninstaller

An Uninstaller.

The uninstaller fires pre and post uninstall hooks. Hooks can be added either through a rubygems_plugin.rb file in an installed gem or via a rubygems/defaults/#{RUBY_ENGINE}.rb or rubygems/defaults/operating_system.rb file. See Gem.pre_uninstall and Gem.post_uninstall for details.

Attributes

bin_dir[R]

The directory a gem’s executables will be installed into

gem_home[R]

The gem repository the gem will be installed into

spec[R]

The Gem::Specification for the gem being uninstalled, only set during #

Public Class Methods

new(gem, options = {}) click to toggle source

Constructs an uninstaller that will uninstall gem

    # File lib/rubygems/uninstaller.rb, line 44
44:   def initialize(gem, options = {})
45:     @gem = gem
46:     @version = options[:version] || Gem::Requirement.default
47:     gem_home = options[:install_dir] || Gem.dir
48:     @gem_home = File.expand_path gem_home
49:     @force_executables = options[:executables]
50:     @force_all = options[:all]
51:     @force_ignore = options[:ignore]
52:     @bin_dir = options[:bin_dir]
53: 
54:     # only add user directory if install_dir is not set
55:     @user_install = false
56:     @user_install = options[:user_install] unless options[:install_dir]
57: 
58:     spec_dir = File.join @gem_home, 'specifications'
59:     @source_index = Gem::SourceIndex.from_gems_in spec_dir
60: 
61:     if @user_install then
62:       user_dir = File.join Gem.user_dir, 'specifications'
63:       @user_index = Gem::SourceIndex.from_gems_in user_dir
64:     end
65:   end

Public Instance Methods

ask_if_ok(spec) click to toggle source
     # File lib/rubygems/uninstaller.rb, line 247
247:   def ask_if_ok(spec)
248:     msg = ['']
249:     msg << 'You have requested to uninstall the gem:'
250:     msg << "\t#{spec.full_name}"
251:     spec.dependent_gems.each do |gem,dep,satlist|
252:       msg <<
253:         ("#{gem.name}-#{gem.version} depends on " +
254:         "[#{dep.name} (#{dep.requirement})]")
255:     end
256:     msg << 'If you remove this gems, one or more dependencies will not be met.'
257:     msg << 'Continue with Uninstall?'
258:     return ask_yes_no(msg.join("\n"), true)
259:   end
dependencies_ok?(spec) click to toggle source
     # File lib/rubygems/uninstaller.rb, line 239
239:   def dependencies_ok?(spec)
240:     return true if @force_ignore
241: 
242:     deplist = Gem::DependencyList.from_source_index @source_index
243:     deplist.add(*@user_index.gems.values) if @user_install
244:     deplist.ok_to_remove?(spec.full_name) || ask_if_ok(spec)
245:   end
path_ok?(gem_dir, spec) click to toggle source

Is spec in gem_dir?

     # File lib/rubygems/uninstaller.rb, line 232
232:   def path_ok?(gem_dir, spec)
233:     full_path = File.join gem_dir, 'gems', spec.full_name
234:     original_path = File.join gem_dir, 'gems', spec.original_name
235: 
236:     full_path == spec.full_gem_path || original_path == spec.full_gem_path
237:   end
remove(spec, list) click to toggle source
spec

the spec of the gem to be uninstalled

list

the list of all such gems

Warning: this method modifies the list parameter. Once it has uninstalled a gem, it is removed from that list.

     # File lib/rubygems/uninstaller.rb, line 181
181:   def remove(spec, list)
182:     unless dependencies_ok? spec then
183:       raise Gem::DependencyRemovalException,
184:             "Uninstallation aborted due to dependent gem(s)"
185:     end
186: 
187:     unless path_ok?(@gem_home, spec) or
188:            (@user_install and path_ok?(Gem.user_dir, spec)) then
189:       e = Gem::GemNotInHomeException.new              "Gem is not installed in directory #{@gem_home}"
190:       e.spec = spec
191: 
192:       raise e
193:     end
194: 
195:     raise Gem::FilePermissionError, spec.installation_path unless
196:       File.writable?(spec.installation_path)
197: 
198:     FileUtils.rm_rf spec.full_gem_path
199: 
200:     original_platform_name = [
201:       spec.name, spec.version, spec.original_platform].join '-'
202: 
203:     spec_dir = File.join spec.installation_path, 'specifications'
204:     gemspec = File.join spec_dir, spec.spec_name
205: 
206:     unless File.exist? gemspec then
207:       gemspec = File.join spec_dir, "#{original_platform_name}.gemspec"
208:     end
209: 
210:     FileUtils.rm_rf gemspec
211: 
212:     cache_dir = File.join spec.installation_path, 'cache'
213:     gem = File.join cache_dir, spec.file_name
214: 
215:     unless File.exist? gem then
216:       gem = File.join cache_dir, "#{original_platform_name}.gem"
217:     end
218: 
219:     FileUtils.rm_rf gem
220: 
221:     Gem::DocManager.new(spec).uninstall_doc
222: 
223:     say "Successfully uninstalled #{spec.full_name}"
224: 
225:     list.delete spec
226:   end
remove_all(list) click to toggle source

Removes all gems in list.

NOTE: removes uninstalled gems from list.

     # File lib/rubygems/uninstaller.rb, line 170
170:   def remove_all(list)
171:     list.dup.each { |spec| uninstall_gem spec, list }
172:   end
remove_executables(spec) click to toggle source

Removes installed executables and batch files (windows only) for gemspec.

     # File lib/rubygems/uninstaller.rb, line 123
123:   def remove_executables(spec)
124:     return if spec.nil?
125: 
126:     unless spec.executables.empty? then
127:       bindir = @bin_dir ? @bin_dir : Gem.bindir(spec.installation_path)
128: 
129:       list = @source_index.find_name(spec.name).delete_if { |s|
130:         s.version == spec.version
131:       }
132: 
133:       executables = spec.executables.clone
134: 
135:       list.each do |s|
136:         s.executables.each do |exe_name|
137:           executables.delete exe_name
138:         end
139:       end
140: 
141:       return if executables.empty?
142: 
143:       answer = if @force_executables.nil? then
144:                  ask_yes_no("Remove executables:\n"                              "\t#{spec.executables.join(", ")}\n\nin addition to the gem?",
145:                             true) # " # appease ruby-mode - don't ask
146:                else
147:                  @force_executables
148:                end
149: 
150:       unless answer then
151:         say "Executables and scripts will remain installed."
152:       else
153:         raise Gem::FilePermissionError, bindir unless File.writable? bindir
154: 
155:         spec.executables.each do |exe_name|
156:           say "Removing #{exe_name}"
157:           FileUtils.rm_f File.join(bindir, exe_name)
158:           FileUtils.rm_f File.join(bindir, "#{exe_name}.bat")
159:         end
160:       end
161:     end
162:   end
uninstall() click to toggle source

Performs the uninstall of the gem. This removes the spec, the Gem directory, and the cached .gem file.

    # File lib/rubygems/uninstaller.rb, line 71
71:   def uninstall
72:     list = @source_index.find_name @gem, @version
73:     list += @user_index.find_name @gem, @version if @user_install
74: 
75:     if list.empty? then
76:       raise Gem::InstallError, "cannot uninstall, check `gem list -d #{@gem}`"
77: 
78:     elsif list.size > 1 and @force_all then
79:       remove_all list.dup
80: 
81:     elsif list.size > 1 then
82:       gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
83: 
84:       say
85:       gem_name, index = choose_from_list "Select gem to uninstall:", gem_names
86: 
87:       if index == list.size then
88:         remove_all list.dup
89:       elsif index >= 0 && index < list.size then
90:         uninstall_gem list[index], list.dup
91:       else
92:         say "Error: must enter a number [1-#{list.size+1}]"
93:       end
94:     else
95:       uninstall_gem list.first, list.dup
96:     end
97:   end
uninstall_gem(spec, specs) click to toggle source

Uninstalls gem spec

     # File lib/rubygems/uninstaller.rb, line 102
102:   def uninstall_gem(spec, specs)
103:     @spec = spec
104: 
105:     Gem.pre_uninstall_hooks.each do |hook|
106:       hook.call self
107:     end
108: 
109:     remove_executables @spec
110:     remove @spec, specs
111: 
112:     Gem.post_uninstall_hooks.each do |hook|
113:       hook.call self
114:     end
115: 
116:     @spec = nil
117:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.