Permalink
Browse files

add --parallel option

  • Loading branch information...
1 parent ad8f02f commit 75a622c5ae345da21421de6669d008e16ff5355f @grosser committed Nov 6, 2010
Showing with 20 additions and 7 deletions.
  1. +2 −0 Readme.md
  2. +8 −4 lib/rubygems/commands/dependent_command.rb
  3. +4 −3 lib/rubygems/dependent.rb
  4. +6 −0 spec/dependent_spec.rb
View
@@ -10,6 +10,8 @@ The first run can take looooong, but after the caches are filled, its pretty fas
--source URL Query this source (e.g. http://rubygems.org)
--no-progress Do not show progress
--fetch-limit N Fetch specs for max N gems (for fast debugging)
+ --parallel N Make N requests in parallel
+
Output
======
@@ -4,16 +4,20 @@ class Gem::Commands::DependentCommand < Gem::Command
def initialize
super 'dependent', 'Show which gems depend on a gem', :progress => true
- add_option('--source URL', 'Query these sources (e.g. http://gemcutter.org)') do |remote, _|
- options[:source] = remote.to_s.split(',')
+ add_option('--source URL', 'Query these sources (e.g. http://gemcutter.org)') do |n, _|
+ options[:source] = n.to_s.split(',')
end
add_option('--no-progress', 'Do not show progress') do
options[:progress] = false
end
- add_option('--fetch-limit N', Integer, 'Fetch specs for max N gems (for fast debugging)') do |limit, _|
- options[:fetch_limit] = limit
+ add_option('--fetch-limit N', Integer, 'Fetch specs for max N gems (for fast debugging)') do |n, _|
+ options[:fetch_limit] = n
+ end
+
+ add_option('--parallel N', Integer, 'Make N requests in parallel') do |n, _|
+ options[:parallel] = n
end
end
@@ -22,7 +22,7 @@ def self.find(gem, options={})
puts "Downloading specs for #{specs_and_sources.size} gems"
end
- gems_and_dependencies = fetch_all_dependencies(specs_and_sources) do
+ gems_and_dependencies = fetch_all_dependencies(specs_and_sources, options) do
print_dot if options[:progress]
end
print "\n" if options[:progress]
@@ -32,8 +32,9 @@ def self.find(gem, options={})
private
- def self.fetch_all_dependencies(specs_and_sources)
- Parallel.map(specs_and_sources, :in_processes => 15) do |spec, source|
+ def self.fetch_all_dependencies(specs_and_sources, options)
+ parallel = (options[:parallel] || 15)
+ Parallel.map(specs_and_sources, :in_processes => parallel) do |spec, source|
yield if block_given?
name = spec.first
dependencies = fetch_dependencies(spec, source)
View
@@ -51,6 +51,12 @@ def stub_source(gem_source = nil)
Gem::Dependent.find('hoe', :source => source)
end
+ it "obeys parallel option" do
+ stub_source
+ Parallel.should_receive(:map).with(anything, :in_processes => 3).and_return []
+ Gem::Dependent.find('hoe', :parallel => 3)
+ end
+
it "has a VERSION" do
Gem::Dependent::VERSION.should =~ /^\d+\.\d+\.\d+$/
end

0 comments on commit 75a622c

Please sign in to comment.