Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • rubygems/commands/pristine_command.rb

Parent

Methods

Included Modules

Class/Module Index [+]

Quicksearch

Gem::Commands::PristineCommand

Public Class Methods

new() click to toggle source
 
               # 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
            

Public Instance Methods

execute() click to toggle source
 
               # 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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus