lib/rubygems/dependent.rb in gem-dependent-0.1.7 vs lib/rubygems/dependent.rb in gem-dependent-0.2.0
- old
+ new
@@ -1,16 +1,15 @@
-require 'rubygems/dependent_parallel'
+require 'rubygems/dependent/version'
+require 'rubygems/dependent/parallel'
require 'rubygems/spec_fetcher'
module Gem
class Dependent
- VERSION = File.read( File.join(File.dirname(__FILE__),'..','..','VERSION') ).strip
-
def self.find(gem, options={})
# get all gems
specs_and_sources = with_changed_gem_source(options[:source]) do
- all_specs_and_sources
+ all_specs_and_sources(:all_versions => options[:all_versions])
end
if options[:fetch_limit]
specs_and_sources = specs_and_sources.first(options[:fetch_limit])
end
@@ -31,46 +30,51 @@
def self.fetch_all_dependencies(specs_and_sources, options)
parallel = (options[:parallel] || 15)
Gem::Dependent::Parallel.map(specs_and_sources, :in_processes => parallel) do |spec, source|
yield if block_given?
- name = spec.first
- dependencies = fetch_dependencies(spec, source)
- [name, dependencies]
+ name, version = spec[0,2]
+ dependencies = fetch_dependencies(spec, source, options)
+ [name, version, dependencies]
end
end
- def self.fetch_dependencies(spec, source)
+ def self.fetch_dependencies(spec, source, options)
begin
fetcher = Gem::SpecFetcher.fetcher
fetcher.fetch_spec(spec, URI.parse(source)).dependencies
rescue Object => e
- $stderr.puts e
+ $stderr.puts e unless options[:all_versions]
[]
end
end
def self.select_dependent(gems_and_dependencies, gem)
- gems_and_dependencies.map do |name, dependencies|
- matching_dependencies = dependencies.select{|d| d.name == gem }
+ gems_and_dependencies.map do |name, version, dependencies|
+ matching_dependencies = dependencies.select{|d| d.name == gem } rescue []
next if matching_dependencies.empty?
- [name, matching_dependencies]
+ [name, version, matching_dependencies]
end.compact
end
def self.print_dot
$stderr.print '.'
$stderr.flush if rand(20) == 0 # make progress visible
end
- def self.all_specs_and_sources
+ def self.all_specs_and_sources(options={})
fetcher = Gem::SpecFetcher.fetcher
all = true
matching_platform = false
prerelease = false
matcher = Gem::Dependency.new(//, Gem::Requirement.default) # any name, any version
specs_and_sources = fetcher.find_matching matcher, all, matching_platform, prerelease
- uniq_by(specs_and_sources){|a| a.first.first }
+
+ if options[:all_versions]
+ specs_and_sources
+ else
+ uniq_by(specs_and_sources){|a| a.first.first }
+ end
end
# get unique elements from an array (last found is used)
# http://drawohara.com/post/146659159/ruby-enumerable-uniq-by
def self.uniq_by(array, &block)