Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more
# File rubygems/commands/pristine_command.rb, line 11 def initialize super 'pristine', 'Restores installed gems to pristine condition from files located in the gem cache', :version => Gem::Requirement.default add_option('--all', 'Restore all installed gems to pristine', 'condition') do |value, options| options[:all] = value end add_version_option('restore to', 'pristine condition') end
# File rubygems/commands/pristine_command.rb, line 51 def execute gem_name = nil specs = if options[:all] then Gem::SourceIndex.from_installed_gems.map do |name, spec| spec end else gem_name = get_one_gem_name Gem::SourceIndex.from_installed_gems.find_name(gem_name, options[:version]) end if specs.empty? then raise Gem::Exception, "Failed to find gem #{gem_name} #{options[:version]}" end install_dir = Gem.dir # TODO use installer option raise Gem::FilePermissionError.new(install_dir) unless File.writable?(install_dir) say "Restoring gem(s) to pristine condition..." specs.each do |spec| gem = Dir[File.join(Gem.dir, 'cache', spec.file_name)].first if gem.nil? then alert_error "Cached gem for #{spec.full_name} not found, use `gem install` to restore" next end # TODO use installer options installer = Gem::Installer.new gem, :wrappers => true, :force => true installer.install say "Restored #{spec.full_name}" end end