Browse files

Moving the app into its own class

  • Loading branch information...
1 parent f611e01 commit e043ecbb575c7a5e7550cadd9453f39456d813bf @qrush qrush committed May 11, 2009
Showing with 41 additions and 32 deletions.
  1. +5 −0 config.ru
  2. +4 −2 lib/gemcutter.rb
  3. +31 −29 lib/gemcutter/app.rb
  4. +1 −1 spec/spec_helper.rb
View
5 config.ru
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'lib/gemcutter'
+set :run, false
+set :environment, :production
+run Gemcutter::App
View
6 lib/gemcutter.rb
@@ -5,9 +5,11 @@
require 'json'
require 'haml'
+require 'gemcutter/app'
require 'gemcutter/helper'
-#require 'gemcutter/app'
+
+module Gemcutter
+end
Gem.configuration.verbose = false
Gemcutter::Helper.indexer.generate_index
-Gemcutter::Helper.host = "http://gemcutter.org"
View
60 lib/gemcutter/app.rb
@@ -1,40 +1,42 @@
-require 'sinatra'
-require File.join(File.dirname(__FILE__), 'helper')
+module Gemcutter
+ class App < Sinatra::Default
-set :app_file, __FILE__
+ set :app_file, __FILE__
-get '/' do
- haml :index
-end
+ get '/' do
+ haml :index
+ end
-get '/gems' do
- cache_path = Gemcutter::Helper.server_path('cache', "*.gem")
- @gems = Dir[cache_path].map do |gem|
- gem = File.basename(gem).split("-")
- "#{gem[0..-2]} (#{gem.last.chomp(".gem")})"
+ get '/gems' do
+ cache_path = Gemcutter::Helper.server_path('cache', "*.gem")
+ @gems = Dir[cache_path].map do |gem|
+ gem = File.basename(gem).split("-")
+ "#{gem[0..-2]} (#{gem.last.chomp(".gem")})"
+ end
+ haml :gems
end
- haml :gems
-end
-get '/gems/:gem' do
- gem = Gemcutter::Helper.server_path('specifications', params[:gem] + "*")
- spec = Gem::Specification.load Dir[gem].first
+ get '/gems/:gem' do
+ gem = Gemcutter::Helper.server_path('specifications', params[:gem] + "*")
+ spec = Gem::Specification.load Dir[gem].first
- content_type "application/json"
- { :name => spec.name, :version => spec.version }.to_json
-end
+ content_type "application/json"
+ { :name => spec.name, :version => spec.version }.to_json
+ end
-post '/gems' do
- spec = Gemcutter::Helper.save_gem(request.body)
+ post '/gems' do
+ spec = Gemcutter::Helper.save_gem(request.body)
- content_type "text/plain"
- status(201)
- "New gem '#{spec.name}' registered."
-end
+ content_type "text/plain"
+ status(201)
+ "New gem '#{spec.name}' registered."
+ end
-put '/gems/:gem' do
- spec = Gemcutter::Helper.save_gem(request.env["rack.input"])
+ put '/gems/:gem' do
+ spec = Gemcutter::Helper.save_gem(request.env["rack.input"])
- content_type "text/plain"
- "Gem '#{spec.name}' version #{spec.version} updated."
+ content_type "text/plain"
+ "Gem '#{spec.name}' version #{spec.version} updated."
+ end
+ end
end
View
2 spec/spec_helper.rb
@@ -27,5 +27,5 @@ def gem_file(name)
end
def app
- Sinatra::Application.new
+ Gemcutter::App.new
end

0 comments on commit e043ecb

Please sign in to comment.