Class: Gem::Commands::OrphanCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/orphan_command.rb

Instance Method Summary collapse

Constructor Details

#initializeOrphanCommand

Returns a new instance of OrphanCommand.



5
6
7
# File 'lib/rubygems/commands/orphan_command.rb', line 5

def initialize
  super 'orphan', 'Show gems which are required from nothing.'
end

Instance Method Details

#executeObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rubygems/commands/orphan_command.rb', line 9

def execute
  specs = Gem::Specification.to_a
  dependencies = specs.map(&:dependencies).flatten.uniq
  runtime_dependencies = dependencies.select {|dep| dep.type == :runtime }

  specs.delete_if {|spec| spec.default_gem? || runtime_dependencies.any? {|dep| dep.name == spec.name} }

  specs.each do |spec|
    say "#{spec.name} (#{spec.version})"
  end
end