Class Gem::Commands::DependencyCommand
In: lib/rubygems/commands/dependency_command.rb
Parent: Gem::Command

Methods

Included Modules

Gem::LocalRemoteOptions Gem::VersionOption

Public Class methods

[Source]

    # File lib/rubygems/commands/dependency_command.rb, line 11
11:   def initialize
12:     super 'dependency',
13:           'Show the dependencies of an installed gem',
14:           :version => Gem::Requirement.default, :domain => :local
15: 
16:     add_version_option
17:     add_platform_option
18: 
19:     add_option('-R', '--[no-]reverse-dependencies',
20:                'Include reverse dependencies in the output') do
21:       |value, options|
22:       options[:reverse_dependencies] = value
23:     end
24: 
25:     add_option('-p', '--pipe',
26:                "Pipe Format (name --version ver)") do |value, options|
27:       options[:pipe_format] = value
28:     end
29: 
30:     add_local_remote_options
31:   end

Public Instance methods

[Source]

     # File lib/rubygems/commands/dependency_command.rb, line 45
 45:   def execute
 46:     options[:args] << '.' if options[:args].empty?
 47:     specs = {}
 48: 
 49:     source_indexes = []
 50: 
 51:     if local? then
 52:       source_indexes << Gem::SourceIndex.from_installed_gems
 53:     end
 54: 
 55:     if remote? then
 56:       Gem::SourceInfoCache.cache_data.map do |_, sice|
 57:         source_indexes << sice.source_index
 58:       end
 59:     end
 60: 
 61:     options[:args].each do |name|
 62:       new_specs = nil
 63:       source_indexes.each do |source_index|
 64:         new_specs =  find_gems(name, source_index)
 65:       end
 66: 
 67:       say "No match found for #{name} (#{options[:version]})" if
 68:         new_specs.empty?
 69: 
 70:       specs = specs.merge new_specs
 71:     end
 72: 
 73:     terminate_interaction 1 if specs.empty?
 74: 
 75:     reverse = Hash.new { |h, k| h[k] = [] }
 76: 
 77:     if options[:reverse_dependencies] then
 78:       specs.values.each do |source_index, spec|
 79:         reverse[spec.full_name] = find_reverse_dependencies spec, source_index
 80:       end
 81:     end
 82: 
 83:     if options[:pipe_format] then
 84:       specs.values.sort_by { |_, spec| spec }.each do |_, spec|
 85:         unless spec.dependencies.empty?
 86:           spec.dependencies.each do |dep|
 87:             say "#{dep.name} --version '#{dep.version_requirements}'"
 88:           end
 89:         end
 90:       end
 91:     else
 92:       response = ''
 93: 
 94:       specs.values.sort_by { |_, spec| spec }.each do |_, spec|
 95:         response << print_dependencies(spec)
 96:         unless reverse[spec.full_name].empty? then
 97:           response << "  Used by\n"
 98:           reverse[spec.full_name].each do |sp, dep|
 99:             response << "    #{sp} (#{dep})\n"
100:           end
101:         end
102:         response << "\n"
103:       end
104: 
105:       say response
106:     end
107:   end

[Source]

     # File lib/rubygems/commands/dependency_command.rb, line 138
138:   def find_gems(name, source_index)
139:     specs = {}
140: 
141:     spec_list = source_index.search name, options[:version]
142: 
143:     spec_list.each do |spec|
144:       specs[spec.full_name] = [source_index, spec]
145:     end
146: 
147:     specs
148:   end

Retuns list of [specification, dep] that are satisfied by spec.

[Source]

     # File lib/rubygems/commands/dependency_command.rb, line 121
121:   def find_reverse_dependencies(spec, source_index)
122:     result = []
123: 
124:     source_index.each do |name, sp|
125:       sp.dependencies.each do |dep|
126:         dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep
127: 
128:         if spec.name == dep.name and
129:            dep.version_requirements.satisfied_by?(spec.version) then
130:           result << [sp.full_name, dep]
131:         end
132:       end
133:     end
134: 
135:     result
136:   end

[Source]

     # File lib/rubygems/commands/dependency_command.rb, line 109
109:   def print_dependencies(spec, level = 0)
110:     response = ''
111:     response << '  ' * level + "Gem #{spec.full_name}\n"
112:     unless spec.dependencies.empty? then
113:       spec.dependencies.each do |dep|
114:         response << '  ' * level + "  #{dep}\n"
115:       end
116:     end
117:     response
118:   end

[Validate]