| Class | Gem::Commands::PristineCommand |
| In: |
lib/rubygems/commands/pristine_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/pristine_command.rb, line 11
11: def initialize
12: super 'pristine',
13: 'Restores installed gems to pristine condition from files located in the gem cache',
14: :version => Gem::Requirement.default
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_version_option('restore to', 'pristine condition')
23: end
# File lib/rubygems/commands/pristine_command.rb, line 52
52: def execute
53: gem_name = nil
54:
55: specs = if options[:all] then
56: Gem::SourceIndex.from_installed_gems.map do |name, spec|
57: spec
58: end
59: else
60: gem_name = get_one_gem_name
61: Gem::SourceIndex.from_installed_gems.find_name(gem_name,
62: options[:version])
63: end
64:
65: if specs.empty? then
66: raise Gem::Exception,
67: "Failed to find gem #{gem_name} #{options[:version]}"
68: end
69:
70: install_dir = Gem.dir # TODO use installer option
71:
72: raise Gem::FilePermissionError.new(install_dir) unless
73: File.writable?(install_dir)
74:
75: say "Restoring gem(s) to pristine condition..."
76:
77: specs.each do |spec|
78: gem = Dir[File.join(Gem.dir, 'cache', "#{spec.full_name}.gem")].first
79:
80: if gem.nil? then
81: alert_error "Cached gem for #{spec.full_name} not found, use `gem install` to restore"
82: next
83: end
84:
85: # TODO use installer options
86: installer = Gem::Installer.new gem, :wrappers => true, :force => true
87: installer.install
88:
89: say "Restored #{spec.full_name}"
90: end
91: end