From 06d3e54f726843081fa1f4c1a61ed42770e009d0 Mon Sep 17 00:00:00 2001 From: _why Date: Wed, 10 May 2006 19:54:42 +0000 Subject: [PATCH] * bin/camping: Now supports Mongrel. Or falls back to WEBrick. --- CHANGELOG | 6 ++++ Rakefile | 2 +- bin/camping | 89 ++++++++++++++++++++++++++++++++++------------------- 3 files changed, 65 insertions(+), 32 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 54f1920..701d335 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ += 1.4.2 +=== 10th May, 2006 + +* Efficient file uploads for multipart/form-data POSTs. +* Camping tool now uses Mongrel, if available. If not, sticks with WEBrick. + = 1.4.1 === 3rd May, 2006 diff --git a/Rakefile b/Rakefile index 55089c1..fab6e05 100644 --- a/Rakefile +++ b/Rakefile @@ -6,7 +6,7 @@ require 'fileutils' include FileUtils NAME = "camping" -VERS = "1.4.1.87" +VERS = "1.4.2" CLEAN.include ['**/.*.sw?', '*.gem', '.config'] RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation", "--template", "extras/flipbook_rdoc.rb", diff --git a/bin/camping b/bin/camping index 730b182..b63cb1f 100755 --- a/bin/camping +++ b/bin/camping @@ -4,16 +4,20 @@ # causing some pain.) RAILS_CONNECTION_ADAPTERS = %w[sqlite] +require 'delegate' require 'stringio' -require 'webrick/httpserver' -require 'camping/webrick' +require 'rubygems' +require 'camping' (puts < 'sqlite3', :database => db -class WEBrick::CampingHandler +class CampingReloader attr_accessor :klass, :mtime -end -# Load the script, locate the module -def camp_load(server, script, klass = nil) - Object.instance_eval { remove_const klass.name } if klass - mtime = File.mtime(script) - load script - klass = Object.const_get(Object.constants.grep(/^#{File.basename(script)[/^(\w+)/,1]}$/i)[0]) rescue nil - klass ||= Camping - klass.create if klass.respond_to? :create - - brick = WEBrick::CampingHandler.new(server, klass) - brick.mtime = mtime - brick -end + def initialize(script) + @script = script + load_app + end + + def load_app + @mtime = File.mtime(@script) + load @script + @klass = Object.const_get(Object.constants.grep(/^#{File.basename(@script)[/^(\w+)/,1]}$/i)[0]) rescue nil + @klass.create if @klass.respond_to? :create + @klass + end + + # Load the script, locate the module + def reload_app + newtime = File.mtime( @script ) + return if @mtime and newtime <= @mtime -# Mount the root -s = WEBrick::HTTPServer.new(:BindAddress => '0.0.0.0', :Port => 3301) -brick = camp_load( s, script ) -s.mount_proc("/") do |req, resp| - newtime = File.mtime( script ) - if newtime > brick.mtime - brick = camp_load( s, script, brick.klass ) + k = @klass + Object.instance_eval { remove_const k.name } if k + load_app + end + + def run(*a) + reload_app + @klass.run(*a) end - brick.do_GET(req, resp) - nil end -# Server up -trap(:INT) do - s.shutdown +begin + require 'mongrel' + require 'mongrel/camping' + config = Mongrel::Configurator.new :host => host do + listener :port => port do + uri "/", :handler => Mongrel::Camping::CampingHandler.new(CampingReloader.new(script)) + uri "/favicon.ico", :handler => Mongrel::Error404Handler.new("") + trap("INT") { stop } + run + end + end + config.join +rescue LoadError + require 'webrick/httpserver' + require 'camping/webrick' + + # Mount the root + s = WEBrick::HTTPServer.new(:BindAddress => host, :Port => port) + s.mount "/", WEBrick::CampingHandler, CampingReloader.new(script) + + # Server up + trap(:INT) do + s.shutdown + end + s.start end -s.start