| Class | Gem::Commands::PristineCommand |
| In: |
lib/rubygems/commands/pristine_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/pristine_command.rb, line 10
10: def initialize
11: super 'pristine',
12: 'Restores installed gems to pristine condition from files located in the gem cache',
13: :version => Gem::Requirement.default
14:
15: add_option('--all',
16: 'Restore all installed gems to pristine',
17: 'condition') do |value, options|
18: options[:all] = value
19: end
20:
21: add_version_option('restore to', 'pristine condition')
22: end
# File lib/rubygems/commands/pristine_command.rb, line 51
51: def execute
52: gem_name = nil
53:
54: specs = if options[:all] then
55: Gem.source_index.map do |name, spec|
56: spec
57: end
58: else
59: gem_name = get_one_gem_name
60: Gem.source_index.find_name(gem_name, options[:version])
61: end
62:
63: if specs.empty? then
64: raise Gem::Exception,
65: "Failed to find gem #{gem_name} #{options[:version]}"
66: end
67:
68: install_dir = Gem.dir # TODO use installer option
69:
70: raise Gem::FilePermissionError.new(install_dir) unless
71: File.writable?(install_dir)
72:
73: say "Restoring gem(s) to pristine condition..."
74:
75: specs.each do |spec|
76: gem = spec.cache_gem
77:
78: if gem.nil? then
79: require 'rubygems/remote_fetcher'
80:
81: say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
82: dep = Gem::Dependency.new spec.name, spec.version
83: Gem::RemoteFetcher.fetcher.download_to_cache dep
84: gem = spec.cache_gem
85: end
86:
87: # TODO use installer options
88: installer = Gem::Installer.new gem, :wrappers => true, :force => true
89: installer.install
90:
91: say "Restored #{spec.full_name}"
92: end
93: end