Class: Gem::Commands::OrphanedCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::OrphanedCommand
- Defined in:
- lib/gem-orphaned/orphaned_command.rb,
lib/gem-orphaned/version.rb
Constant Summary collapse
- PreferredGemsFile =
File.('~/.preferred_gems')
- DefaultPreferredGems =
%w{ bundler gem-orphaned rubygems-update }- VERSION =
'0.4'
Instance Method Summary collapse
- #check_preferred_gems ⇒ Object
- #default_gems ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ OrphanedCommand
constructor
A new instance of OrphanedCommand.
- #orphaned_gems ⇒ Object
- #read_gems ⇒ Object
- #read_preferred_gems ⇒ Object
- #show_orphaned_gems ⇒ Object
Constructor Details
#initialize ⇒ OrphanedCommand
Returns a new instance of OrphanedCommand.
12 13 14 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 12 def initialize super 'orphaned', 'Show orphaned gems' end |
Instance Method Details
#check_preferred_gems ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 42 def check_preferred_gems @preferred_gems.each do |name| unless @gems[name] puts "#{name}: in preferred list but not installed" end end end |
#default_gems ⇒ Object
56 57 58 59 60 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 56 def default_gems @gems.select do |name, specs| specs.find(&:default_gem?) end.keys end |
#execute ⇒ Object
16 17 18 19 20 21 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 16 def execute read_gems read_preferred_gems check_preferred_gems show_orphaned_gems end |
#orphaned_gems ⇒ Object
62 63 64 65 66 67 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 62 def orphaned_gems names = @gems.keys - @preferred_gems @gems.values_at(*names).map do |specs| specs.select { |s| s.dependent_gems.empty? } end.flatten end |
#read_gems ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 23 def read_gems @gems = {} Gem::Specification.each do |spec| @gems[spec.name] ||= [] @gems[spec.name] << spec end end |
#read_preferred_gems ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 31 def read_preferred_gems @preferred_gems = DefaultPreferredGems @preferred_gems += default_gems if File.exist?(PreferredGemsFile) data = File.read(PreferredGemsFile) lines = data.split("\n").map { |s| s.sub(/#.*/, '').strip }.reject(&:empty?) @preferred_gems += lines end @preferred_gems.uniq! end |
#show_orphaned_gems ⇒ Object
50 51 52 53 54 |
# File 'lib/gem-orphaned/orphaned_command.rb', line 50 def show_orphaned_gems orphaned_gems.each do |spec| puts "#{spec.name} (#{spec.version}): orphaned" end end |