Class: Gem::Commands::DependencyCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::DependencyCommand
- Includes:
- LocalRemoteOptions, VersionOption
- Defined in:
- lib/rubygems/commands/dependency_command.rb
Instance Attribute Summary
Attributes inherited from Gem::Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#defaults_str ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#find_reverse_dependencies(spec) ⇒ Object
Returns an Array of [specification, dep] that are satisfied by
spec
. -
#initialize ⇒ DependencyCommand
constructor
A new instance of DependencyCommand.
- #print_dependencies(spec, level = 0) ⇒ Object
-
#usage ⇒ Object
:nodoc:.
Methods included from VersionOption
#add_platform_option, #add_prerelease_option, #add_version_option
Methods included from LocalRemoteOptions
#accept_uri_http, #add_bulk_threshold_option, #add_clear_sources_option, #add_local_remote_options, #add_proxy_option, #add_source_option, #add_update_sources_option, #both?, #local?, #remote?
Methods inherited from Gem::Command
add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, common_options, #description, extra_args, extra_args=, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from UserInteraction
#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize ⇒ DependencyCommand
Returns a new instance of DependencyCommand.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubygems/commands/dependency_command.rb', line 10 def initialize super 'dependency', 'Show the dependencies of an installed gem', :version => Gem::Requirement.default, :domain => :local add_version_option add_platform_option add_prerelease_option add_option('-R', '--[no-]reverse-dependencies', 'Include reverse dependencies in the output') do |value, | [:reverse_dependencies] = value end add_option('-p', '--pipe', "Pipe Format (name --version ver)") do |value, | [:pipe_format] = value end end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
33 34 35 |
# File 'lib/rubygems/commands/dependency_command.rb', line 33 def arguments # :nodoc: "GEMNAME name of gem to show dependencies for" end |
#defaults_str ⇒ Object
:nodoc:
37 38 39 |
# File 'lib/rubygems/commands/dependency_command.rb', line 37 def defaults_str # :nodoc: "--local --version '#{Gem::Requirement.default}' --no-reverse-dependencies" end |
#execute ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rubygems/commands/dependency_command.rb', line 45 def execute if [:reverse_dependencies] and remote? and not local? then alert_error 'Only reverse dependencies for local gems are supported.' terminate_interaction 1 end [:args] << '' if [:args].empty? pattern = if [:args].length == 1 and [:args].first =~ /\A\/(.*)\/(i)?\z/m then flags = $2 ? Regexp::IGNORECASE : nil Regexp.new $1, flags else /\A#{Regexp.union(*options[:args])}/ end # TODO: deprecate for real damnit dependency = Gem::Deprecate.skip_during { Gem::Dependency.new pattern, [:version] } dependency.prerelease = [:prerelease] specs = [] specs.concat dependency.matching_specs if local? if remote? and not [:reverse_dependencies] then fetcher = Gem::SpecFetcher.fetcher # REFACTOR: fetcher.find_specs_matching => specs specs_and_sources = fetcher.find_matching(dependency, dependency.specific?, true, dependency.prerelease?) specs.concat specs_and_sources.map { |spec_tuple, source_uri| fetcher.fetch_spec spec_tuple, URI.parse(source_uri) } end if specs.empty? then patterns = [:args].join ',' say "No gems found matching #{patterns} (#{options[:version]})" if Gem.configuration.verbose terminate_interaction 1 end specs = specs.uniq.sort reverse = Hash.new { |h, k| h[k] = [] } if [:reverse_dependencies] then specs.each do |spec| reverse[spec.full_name] = find_reverse_dependencies spec end end if [:pipe_format] then specs.each do |spec| unless spec.dependencies.empty? spec.dependencies.sort_by { |dep| dep.name }.each do |dep| say "#{dep.name} --version '#{dep.requirement}'" end end end else response = '' specs.each do |spec| response << print_dependencies(spec) unless reverse[spec.full_name].empty? then response << " Used by\n" reverse[spec.full_name].each do |sp, dep| response << " #{sp} (#{dep})\n" end end response << "\n" end say response end end |
#find_reverse_dependencies(spec) ⇒ Object
Returns an Array of [specification, dep] that are satisfied by spec
.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rubygems/commands/dependency_command.rb', line 142 def find_reverse_dependencies(spec) result = [] Gem::Specification.each do |sp| sp.dependencies.each do |dep| dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep if spec.name == dep.name and dep.requirement.satisfied_by?(spec.version) then result << [sp.full_name, dep] end end end result end |
#print_dependencies(spec, level = 0) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rubygems/commands/dependency_command.rb', line 128 def print_dependencies(spec, level = 0) response = '' response << ' ' * level + "Gem #{spec.full_name}\n" unless spec.dependencies.empty? then spec.dependencies.sort_by { |dep| dep.name }.each do |dep| response << ' ' * level + " #{dep}\n" end end response end |
#usage ⇒ Object
:nodoc:
41 42 43 |
# File 'lib/rubygems/commands/dependency_command.rb', line 41 def usage # :nodoc: "#{program_name} GEMNAME" end |