Sha256: 810e58ac945888718e0934017e5b13d3ad90795cb109e08cf8a894ebf7d4c8c0
Contents?: true
Size: 1.64 KB
Versions: 3
Compression:
Stored size: 1.64 KB
Contents
require "builder" require 'sinatra/base' require 'rubygems' require "rubygems/indexer" require 'hostess' class Geminabox < Sinatra::Base enable :static, :methodoverride set :public, File.join(File.dirname(__FILE__), *%w[.. public]) set :data, File.join(File.dirname(__FILE__), *%w[.. data]) set :views, File.join(File.dirname(__FILE__), *%w[.. views]) use Hostess get '/' do begin @gems = Marshal.load(Gem.gunzip(Gem.read_binary( File.join(options.data, "specs.#{Gem.marshal_version}.gz")) )) rescue @gems = [] end erb :index end get '/upload' do erb :upload end delete '/gems/*.gem' do File.delete file_path if File.exists? file_path reindex redirect "/" end post '/upload' do unless params[:file] && (tmpfile = params[:file][:tempfile]) && (name = params[:file][:filename]) @error = "No file selected" return erb(:upload) end Dir.mkdir(File.join(options.data, "gems")) unless File.directory? File.join(options.data, "gems") File.open(File.join(options.data, "gems", File.basename(name)), "w") do |f| while blk = tmpfile.read(65536) f << blk end end reindex redirect "/" end private def reindex Gem::Indexer.new(options.data).generate_index end def file_path File.expand_path(File.join(options.data, *request.path_info)) end helpers do def url_for(path) url = request.scheme + "://" url << request.host if request.scheme == "https" && request.port != 443 || request.scheme == "http" && request.port != 80 url << ":#{request.port}" end url << path end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
geminabox-0.2.1 | lib/geminabox.rb |
geminabox-0.2.0 | lib/geminabox.rb |
geminabox-0.1.0 | lib/geminabox.rb |