# 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, :extensions => true,
14: :all => false
15:
16: add_option('--all',
17: 'Restore all installed gems to pristine',
18: 'condition') do |value, options|
19: options[:all] = value
20: end
21:
22: add_option('--[no-]extensions',
23: 'Restore gems with extensions') do |value, options|
24: options[:extensions] = value
25: end
26:
27: add_version_option('restore to', 'pristine condition')
28: end
# File lib/rubygems/commands/pristine_command.rb, line 59
59: def execute
60: specs = if options[:all] then
61: Gem::Specification.map
62: else
63: get_all_gem_names.map do |gem_name|
64: Gem::Specification.find_all_by_name gem_name, options[:version]
65: end.flatten
66: end
67:
68: if specs.to_a.empty? then
69: raise Gem::Exception,
70: "Failed to find gems #{options[:args]} #{options[:version]}"
71: end
72:
73: install_dir = Gem.dir # TODO use installer option
74:
75: raise Gem::FilePermissionError.new(install_dir) unless
76: File.writable?(install_dir)
77:
78: say "Restoring gems to pristine condition..."
79:
80: specs.each do |spec|
81: unless spec.extensions.empty? or options[:extensions] then
82: say "Skipped #{spec.full_name}, it needs to compile an extension"
83: next
84: end
85:
86: gem = spec.cache_file
87:
88: unless File.exist? gem then
89: require 'rubygems/remote_fetcher'
90:
91: say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
92: dep = Gem::Dependency.new spec.name, spec.version
93: Gem::RemoteFetcher.fetcher.download_to_cache dep
94: end
95:
96: # TODO use installer options
97: installer = Gem::Installer.new(gem,
98: :wrappers => true,
99: :force => true,
100: :install_dir => spec.base_dir)
101: installer.install
102:
103: say "Restored #{spec.full_name}"
104: end
105: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.