Skip to content
Browse files

pass meaningfull options instead of flags

  • Loading branch information...
1 parent 5f3ad21 commit 03770e4aa77b9fc6b4c14b09dedd0b3f42e4adb5 @grosser committed May 7, 2012
Showing with 19 additions and 14 deletions.
  1. +2 −2 lib/rubygems/commands/dependent_command.rb
  2. +8 −3 lib/rubygems/dependent.rb
  3. +9 −9 spec/dependent_spec.rb
View
4 lib/rubygems/commands/dependent_command.rb
@@ -44,7 +44,7 @@ def execute
requirements = dependencies.map do |dependency|
formatted_dependency(dependency)
end.join(', ')
- version = options[:all_versions] ? " (v#{version})" : nil
+ version = (options[:all_versions] ? " (v#{version})" : "")
puts "#{gem}#{version} #{requirements}"
end
rescue Object => e
@@ -58,4 +58,4 @@ def formatted_dependency(dependency)
type = " (#{dependency.type})" if dependency.type == :development
"#{dependency.requirement}#{type}"
end
-end
+end
View
11 lib/rubygems/dependent.rb
@@ -7,7 +7,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(options[:all_versions])
+ all_specs_and_sources(:all_versions => options[:all_versions])
end
if options[:fetch_limit]
@@ -61,14 +61,19 @@ def self.print_dot
$stderr.flush if rand(20) == 0 # make progress visible
end
- def self.all_specs_and_sources(all_versions = false)
+ 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
- all_versions ? specs_and_sources : 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)
View
18 spec/dependent_spec.rb
@@ -23,33 +23,33 @@
]
}
- def simplify(dependencies)
+ def simplify_gem_results(dependencies)
dependencies.map{|name, version, deps| [name, deps.map{|d| d.name}] }
end
- def stub_source(gem_source = nil, check_against_fixtures = true)
- gem_source ||= 'http://gemcutter.org'
- if check_against_fixtures
+ def stub_source(options={})
+ gem_source = options[:source] || 'http://gemcutter.org'
+ if !options[:live]
Gem::SpecFetcher.fetcher.should_receive(:load_specs).with(URI.parse(gem_source), 'specs').and_return(fixture)
end
Gem.sources = [gem_source]
end
it 'finds dependencies for given gem' do
stub_source
- dependencies = simplify(Gem::Dependent.find('hoe'))
+ dependencies = simplify_gem_results(Gem::Dependent.find('hoe'))
dependencies.should == hoe_gems
end
it "obeys fetch-limit" do
stub_source
- dependencies = simplify(Gem::Dependent.find('hoe', :fetch_limit => 100))
+ dependencies = simplify_gem_results(Gem::Dependent.find('hoe', :fetch_limit => 100))
dependencies.should == hoe_gems.first(3)
end
it "can use given source" do
source = 'http://rubygems.org'
- stub_source(source)
+ stub_source(:source => source)
Gem::Dependent.find('hoe', :source => source)
end
@@ -60,8 +60,8 @@ def stub_source(gem_source = nil, check_against_fixtures = true)
end
it "obeys all versions option" do
- stub_source(nil, false)
- Gem::Dependent.should_receive(:all_specs_and_sources).with(true)
+ stub_source :live => true
+ Gem::Dependent.should_receive(:all_specs_and_sources).with(:all_versions => true)
Gem::Dependent.find('hoe', :all_versions => true)
end

0 comments on commit 03770e4

Please sign in to comment.
Something went wrong with that request. Please try again.