Skip to content

Commit

Permalink
Moving the server_path helper out to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed May 25, 2009
1 parent c3382c2 commit b5a13e6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
2 changes: 2 additions & 0 deletions app/app.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
$:.unshift File.expand_path(File.dirname(__FILE__))
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))

require 'rubygems'
require 'sinatra'
require 'json'
require 'haml'
require 'gemcutter'

require 'cutter'
require 'indexer'
Expand Down
18 changes: 7 additions & 11 deletions app/cutter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ def initialize(data)
self.data = data
end

def self.server_path(*more)
File.join(File.dirname(__FILE__), '..', 'server', *more)
end

def self.indexer
indexer = Indexer.new(server_path, :build_legacy => false)
indexer = Indexer.new(Gemcutter.server_path, :build_legacy => false)
def indexer.say(message) end
indexer
end

def self.find_all
all_gems = Marshal.load(File.open(Cutter.server_path("latest_specs.4.8")))
all_gems = Marshal.load(File.open(Gemcutter.server_path("latest_specs.4.8")))
unique_gems = {}

all_gems.each do |gem|
Expand All @@ -32,7 +28,7 @@ def self.find_all
end

def self.find(gem)
path = Cutter.server_path('specifications', gem + "*")
path = Gemcutter.server_path('specifications', gem + "*")
Specification.load Dir[path].last
end

Expand Down Expand Up @@ -74,8 +70,8 @@ def save(temp)

name = "#{self.spec.name}-#{self.spec.version}.gem"

cache_path = Cutter.server_path('cache', name)
spec_path = Cutter.server_path('specifications', name + "spec")
cache_path = Gemcutter.server_path('cache', name)
spec_path = Gemcutter.server_path('specifications', name + "spec")

self.exists = File.exists?(spec_path)

Expand All @@ -89,7 +85,7 @@ def save(temp)
end

def index
source_path = Cutter.server_path("source_index")
source_path = Gemcutter.server_path("source_index")

if File.exists?(source_path)
source_index = Marshal.load(File.open(source_path))
Expand All @@ -106,7 +102,7 @@ def index
Cutter.indexer.abbreviate self.spec
Cutter.indexer.sanitize self.spec

quick_path = Cutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{self.spec.name}-#{self.spec.version}.gemspec.rz")
quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{self.spec.name}-#{self.spec.version}.gemspec.rz")

zipped = Gem.deflate(Marshal.dump(self.spec))
File.open(quick_path, "wb") do |f|
Expand Down
5 changes: 4 additions & 1 deletion lib/gemcutter.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module Gemcutter
class Gemcutter
def self.server_path(*more)
File.join(File.dirname(__FILE__), '..', 'server', *more)
end
end
12 changes: 6 additions & 6 deletions spec/cutter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def mock_save_and_index
mock(Gem::Cutter).indexer.stub!.sanitize(@spec)

marshal = "marshal"
quick_path = Gem::Cutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{@spec.name}-#{@spec.version}.gemspec.rz")
quick_path = Gemcutter.server_path("quick", "Marshal.#{Gem.marshal_version}", "#{@spec.name}-#{@spec.version}.gemspec.rz")

mock(Marshal).dump(@spec) { mock(Gem).deflate(stub!) }
mock(File).open(quick_path, 'wb')
Expand All @@ -39,18 +39,18 @@ def mock_save_and_index
@gem_file = gem_file(@gem)
@gem_up = "test-0.0.0.gem_up"
@gem_up_file = gem_file(@gem_up)
@cache_path = Gem::Cutter.server_path("cache", @gem)
@spec_path = Gem::Cutter.server_path("specifications", @gem + "spec")
@cache_path = Gemcutter.server_path("cache", @gem)
@spec_path = Gemcutter.server_path("specifications", @gem + "spec")
@temp_path = "temp path"

regenerate_index

stub(Tempfile).new("gem").stub!.path { @temp_path }
stub(File).exists?(Gem::Cutter.server_path("source_index")) { false }
stub(File).exists?(Gemcutter.server_path("source_index")) { false }
stub(File).exists?(@cache_path) { false }
stub(File).exists?(@spec_path) { false }
stub(File).open(@temp_path, 'wb')
stub(File).open(Gem::Cutter.server_path("source_index"), 'wb')
stub(File).open(Gemcutter.server_path("source_index"), 'wb')
stub(File).size(@temp_path) { 42 }
end

Expand Down Expand Up @@ -109,7 +109,7 @@ def mock_save_and_index
@rake = ["rake", Gem::Version.new("0.3.7"), "ruby"]

data = "data"
mock(File).open(Gem::Cutter.server_path("latest_specs.4.8")) { data }
mock(File).open(Gemcutter.server_path("latest_specs.4.8")) { data }
mock(Marshal).load(data) { [@rake, @rails1, @rails2] }
end
it "should find all unique gems" do
Expand Down
10 changes: 5 additions & 5 deletions spec/indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
it "should index properly" do
mock(Dir).tmpdir { @tmpdir }

mock.proxy(Gem::Indexer).new(Gem::Cutter.server_path, :build_legacy => false) do |indexer|
mock.proxy(Gem::Indexer).new(Gemcutter.server_path, :build_legacy => false) do |indexer|
mock(indexer).make_temp_directories
mock(indexer).gem_file_list { [@gem] }
stub(indexer).update_specs_index
mock(indexer).compress_indicies
end

# Faking it out so there's a new gem to update
mock(File).mtime(Gem::Cutter.server_path("specs.4.8")) { Time.at 1 }
mock(File).mtime(Gemcutter.server_path("specs.4.8")) { Time.at 1 }
mock(File).mtime(@gem) { @time }

# Loading the cached source index
source_index_data = "source index data"
source_index = "source index"
stub(source_index).prerelease_gems
mock(File).open(Gem::Cutter.server_path("source_index")) { source_index_data }
mock(File).open(Gemcutter.server_path("source_index")) { source_index_data }
mock(Marshal).load(source_index_data) { source_index }

# Moving the compressed specs into place
Expand All @@ -38,10 +38,10 @@
"/prerelease_specs.4.8.gz"].each do |spec|

mock(FileUtils).mv(File.join(@tmpdir, "gem_generate_index_#{$$}", spec),
Gem::Cutter.server_path + "/",
Gemcutter.server_path + "/",
:force => true)

mock(File).utime(@time, @time, Gem::Cutter.server_path + "/")
mock(File).utime(@time, @time, Gemcutter.server_path + "/")
end


Expand Down

0 comments on commit b5a13e6

Please sign in to comment.