Permalink
Browse files

Merge pull request #95 from whitepages/fix_missing_spec_crash

Fix crash when gemspec is missing for a named gem
  • Loading branch information...
2 parents c5c369a + 5939e48 commit f8860f55b9685e37a605e58052248c72fba5b223 @tomlea committed Feb 24, 2013
Showing with 25 additions and 15 deletions.
  1. +25 −15 lib/geminabox.rb
View
@@ -54,21 +54,6 @@ def fixup_bundler_rubygems!
erb :atom, :layout => false
end
- # Return a list of versions of gem 'gem_name' with the dependencies of each version.
- def gem_dependencies(gem_name)
- dependency_cache.marshal_cache(gem_name) do
- load_gems.select {|gem| gem_name == gem.name }.map do |gem|
- spec = spec_for(gem.name, gem.number)
- {
- :name => gem.name,
- :number => gem.number.version,
- :platform => gem.platform,
- :dependencies => spec.dependencies.select {|dep| dep.type == :runtime}.map {|dep| [dep.name, dep.requirement.to_s] }
- }
- end
- end
- end
-
get '/api/v1/dependencies' do
query_gems = params[:gems].split(',')
deps = query_gems.inject([]){|memo, query_gem| memo + gem_dependencies(query_gem) }
@@ -253,5 +238,30 @@ def spec_for(gem_name, version)
spec_file = File.join(settings.data, "quick", "Marshal.#{Gem.marshal_version}", "#{gem_name}-#{version}.gemspec.rz")
Marshal.load(Gem.inflate(File.read(spec_file))) if File.exists? spec_file
end
+
+ # Return a list of versions of gem 'gem_name' with the dependencies of each version.
+ def gem_dependencies(gem_name)
+ dependency_cache.marshal_cache(gem_name) do
+ load_gems.
+ select { |gem| gem_name == gem.name }.
+ map { |gem| [gem, spec_for(gem.name, gem.number)] }.
+ reject { |(_, spec)| spec.nil? }.
+ map do |(gem, spec)|
+ {
+ :name => gem.name,
+ :number => gem.number.version,
+ :platform => gem.platform,
+ :dependencies => runtime_dependencies(spec)
+ }
+ end
+ end
+ end
+
+ def runtime_dependencies(spec)
+ spec.
+ dependencies.
+ select { |dep| dep.type == :runtime }.
+ map { |dep| [dep.name, dep.requirement.to_s] }
+ end
end
end

0 comments on commit f8860f5

Please sign in to comment.