method

execute

Importance_0
v1_9_3_125 - Show latest stable - 0 notes - Class: DependencyCommand
execute() public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/rubygems/commands/dependency_command.rb, line 45
  def execute
    if options[:reverse_dependencies] and remote? and not local? then
      alert_error 'Only reverse dependencies for local gems are supported.'
      terminate_interaction 1
    end

    options[:args] << '' if options[:args].empty?

    pattern = if options[:args].length == 1 and
                 options[:args].first =~ /\A\/(.*)\/(i)?\z/ 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, options[:version]
    }
    dependency.prerelease = options[:prerelease]

    specs = []

    specs.concat dependency.matching_specs if local?

    if remote? and not options[: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 = options[: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 options[:reverse_dependencies] then
      specs.each do |spec|
        reverse[spec.full_name] = find_reverse_dependencies spec
      end
    end

    if options[: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
Register or log in to add new notes.