Skip to content

Commit

Permalink
Add a new option: --all-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Patuzzo committed May 7, 2012
1 parent 8c0bf32 commit d8a4f95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lib/rubygems/commands/dependent_command.rb
Expand Up @@ -19,6 +19,10 @@ def initialize
add_option('--parallel N', Integer, 'Make N requests in parallel') do |n, _|
options[:parallel] = n
end

add_option('--all-versions', 'Check against all versions of gems') do
options[:all_versions] = true
end
end

def arguments
Expand Down
6 changes: 3 additions & 3 deletions lib/rubygems/dependent.rb
Expand Up @@ -8,7 +8,7 @@ class Dependent
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(options[:all_versions])
end

if options[:fetch_limit]
Expand Down Expand Up @@ -62,14 +62,14 @@ def self.print_dot
$stderr.flush if rand(20) == 0 # make progress visible
end

def self.all_specs_and_sources
def self.all_specs_and_sources(all_versions = false)
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 }
all_versions ? specs_and_sources : uniq_by(specs_and_sources){|a| a.first.first }
end

# get unique elements from an array (last found is used)
Expand Down
12 changes: 10 additions & 2 deletions spec/dependent_spec.rb
Expand Up @@ -27,9 +27,11 @@ def simplify(dependencies)
dependencies.map{|name, deps| [name, deps.map{|d| d.name}] }
end

def stub_source(gem_source = nil)
def stub_source(gem_source = nil, check_against_fixtures = true)
gem_source ||= 'http://gemcutter.org'
Gem::SpecFetcher.fetcher.should_receive(:load_specs).with(URI.parse(gem_source), 'specs').and_return(fixture)
if check_against_fixtures
Gem::SpecFetcher.fetcher.should_receive(:load_specs).with(URI.parse(gem_source), 'specs').and_return(fixture)
end
Gem.sources = [gem_source]
end

Expand Down Expand Up @@ -57,6 +59,12 @@ def stub_source(gem_source = nil)
Gem::Dependent.find('hoe', :parallel => 3)
end

it "obeys all versions option" do
stub_source(nil, false)
Gem::Dependent.should_receive(:all_specs_and_sources).with(true)
Gem::Dependent.find('hoe', :all_versions => true)
end

it "has a VERSION" do
Gem::Dependent::VERSION.should =~ /^\d+\.\d+\.\d+$/
end
Expand Down

0 comments on commit d8a4f95

Please sign in to comment.