Skip to content
Browse files

Building dependencies when building a gem

  • Loading branch information...
1 parent ba41579 commit 04cb46f38aac6b74b72291d03ee45f41c8d1d3cf @qrush qrush committed May 31, 2009
Showing with 73 additions and 33 deletions.
  1. +6 −0 Rakefile
  2. +1 −0 app/models/dependency.rb
  3. +38 −33 app/models/rubygem.rb
  4. +1 −0 test/unit/dependency_test.rb
  5. +27 −0 test/unit/rubygem_test.rb
View
6 Rakefile
@@ -100,6 +100,12 @@ namespace :import do
gems.each do |path|
puts path
spec = Rubygem.pull_spec(path)
+
+ if spec.nil?
+ puts "Bad gem: #{path}"
+ next
+ end
+
rubygem = Rubygem.find_or_initialize_by_name(spec.name)
rubygem.spec = spec
rubygem.path = path
View
1 app/models/dependency.rb
@@ -1,4 +1,5 @@
class Dependency < ActiveRecord::Base
belongs_to :rubygem
+ validates_presence_of :name, :requirement
end
View
71 app/models/rubygem.rb
@@ -39,50 +39,55 @@ def with_downloads
"#{name} (#{downloads})"
end
- protected
- def build
- return unless self.spec
+ def build
+ return unless self.spec
- self.name = self.spec.name if self.name.blank?
+ self.name = self.spec.name if self.name.blank?
- version = self.versions.build(
- :authors => self.spec.authors.join(", "),
- :description => self.spec.description || self.spec.summary,
- :created_at => self.spec.date,
- :number => self.spec.version.to_s)
- end
+ version = self.versions.build(
+ :authors => self.spec.authors.join(", "),
+ :description => self.spec.description || self.spec.summary,
+ :created_at => self.spec.date,
+ :number => self.spec.original_name.gsub("#{self.spec.name}-", ''))
- def store
- return unless self.spec
+ self.spec.dependencies.each do |dependency|
+ self.dependencies.build(
+ :name => dependency.name,
+ :requirement => dependency.requirements_list.to_s)
+ end
+ end
- cache = Gemcutter.server_path('gems', "#{self.spec.original_name}.gem")
- FileUtils.cp self.path, cache
- File.chmod 0644, cache
+ def store
+ return unless self.spec
- source_path = Gemcutter.server_path("source_index")
+ cache = Gemcutter.server_path('gems', "#{self.spec.original_name}.gem")
+ FileUtils.cp self.path, cache
+ File.chmod 0644, cache
- if File.exists?(source_path)
- source_index = Marshal.load(File.open(source_path))
- else
- source_index = Gem::SourceIndex.new
- end
+ source_path = Gemcutter.server_path("source_index")
- source_index.add_spec self.spec, self.spec.original_name
+ if File.exists?(source_path)
+ source_index = Marshal.load(File.open(source_path))
+ else
+ source_index = Gem::SourceIndex.new
+ end
- File.open(source_path, "wb") do |f|
- f.write Marshal.dump(source_index)
- end
+ source_index.add_spec self.spec, self.spec.original_name
- Gemcutter.indexer.abbreviate self.spec
- Gemcutter.indexer.sanitize self.spec
+ File.open(source_path, "wb") do |f|
+ f.write Marshal.dump(source_index)
+ end
- quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{self.spec.original_name}.gemspec.rz")
+ Gemcutter.indexer.abbreviate self.spec
+ Gemcutter.indexer.sanitize self.spec
- zipped = Gem.deflate(Marshal.dump(self.spec))
- File.open(quick_path, "wb") do |f|
- f.write zipped
- end
+ quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{self.spec.original_name}.gemspec.rz")
- Gemcutter.indexer.update_index
+ zipped = Gem.deflate(Marshal.dump(self.spec))
+ File.open(quick_path, "wb") do |f|
+ f.write zipped
end
+
+ Gemcutter.indexer.update_index
+ end
end
View
1 test/unit/dependency_test.rb
@@ -2,6 +2,7 @@
class DependencyTest < ActiveSupport::TestCase
should_belong_to :rubygem
+ should_validate_presence_of :name, :requirement
should "be valid with factory" do
assert_valid Factory.build(:dependency)
View
27 test/unit/rubygem_test.rb
@@ -26,6 +26,33 @@ class RubygemTest < ActiveSupport::TestCase
should "return name with downloads for #with_downloads" do
assert_equal "#{@rubygem.name} (#{@rubygem.downloads})", @rubygem.with_downloads
end
+
+ should "save dependencies" do
+ spec = Rubygem.pull_spec(gem_file.path)
+ spec.add_dependency("liquid", ">= 1.9.0")
+ spec.add_dependency("open4", "= 0.9.6")
+ @rubygem.spec = spec
+ @rubygem.build
+
+ assert_equal 2, @rubygem.dependencies.size
+
+ assert_equal "liquid", @rubygem.dependencies.first.name
+ assert_equal ">= 1.9.0", @rubygem.dependencies.first.requirement
+
+ assert_equal "open4", @rubygem.dependencies.last.name
+ assert_equal "= 0.9.6", @rubygem.dependencies.last.requirement
+ end
+
+ should "include platform when saving version" do
+ spec = Rubygem.pull_spec(gem_file.path)
+ spec.platform = "mswin"
+ @rubygem.spec = spec
+ @rubygem.build
+
+ version = @rubygem.current_version
+ assert_not_nil version
+ assert_equal "0.0.0-mswin", version.number
+ end
end
should "pull spec out of the given gem" do

0 comments on commit 04cb46f

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