Method: Gem::Commands::UninstallCommand#uninstall_specific

Defined in:
lib/rubygems/commands/uninstall_command.rb

#uninstall_specificObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/rubygems/commands/uninstall_command.rb', line 151

def uninstall_specific
  deplist = Gem::DependencyList.new
  original_gem_version = {}

  get_all_gem_names_and_versions.each do |name, version|
    original_gem_version[name] = version || options[:version]

    gem_specs = Gem::Specification.find_all_by_name(name, original_gem_version[name])

    if gem_specs.empty?
      say("Gem '#{name}' is not installed")
    else
      gem_specs.reject!(&:default_gem?) if gem_specs.size > 1

      gem_specs.each do |spec|
        deplist.add spec
      end
    end
  end

  deps = deplist.strongly_connected_components.flatten.reverse

  gems_to_uninstall = {}

  deps.each do |dep|
    if original_gem_version[dep.name] == Gem::Requirement.default
      next if gems_to_uninstall[dep.name]
      gems_to_uninstall[dep.name] = true
    else
      options[:version] = dep.version
    end

    uninstall_gem(dep.name)
  end
end