| 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, :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 60
60: def execute
61: specs = if options[:all] then
62: Gem::Specification.map
63: else
64: get_all_gem_names.map do |gem_name|
65: Gem::Specification.find_all_by_name gem_name, options[:version]
66: end.flatten
67: end
68:
69: if specs.to_a.empty? then
70: raise Gem::Exception,
71: "Failed to find gems #{options[:args]} #{options[:version]}"
72: end
73:
74: install_dir = Gem.dir # TODO use installer option
75:
76: raise Gem::FilePermissionError.new(install_dir) unless
77: File.writable?(install_dir)
78:
79: say "Restoring gems to pristine condition..."
80:
81: specs.each do |spec|
82: unless spec.extensions.empty? or options[:extensions] then
83: say "Skipped #{spec.full_name}, it needs to compile an extension"
84: next
85: end
86:
87: gem = spec.cache_file
88:
89: unless File.exist? gem then
90: require 'rubygems/remote_fetcher'
91:
92: say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
93: dep = Gem::Dependency.new spec.name, spec.version
94: Gem::RemoteFetcher.fetcher.download_to_cache dep
95: end
96:
97: # TODO use installer options
98: installer = Gem::Installer.new(gem,
99: :wrappers => true,
100: :force => true,
101: :install_dir => spec.base_dir)
102: installer.install
103:
104: say "Restored #{spec.full_name}"
105: end
106: end