about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-28 19:43:06 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-28 19:43:06 -0800
commit5682d2879258f3ca06b28d4a1a7671b20f676dac (patch)
tree750d52fe56fb3120871f876b6e997a6307af647d
parent3e20bd4576d9fd5499913e37e710e1715eb33ed9 (diff)
downloadzbatery-5682d2879258f3ca06b28d4a1a7671b20f676dac.tar.gz
use Unicorn.builder to parse config.ru switches
Less code to maintain this way.
-rwxr-xr-xbin/zbatery42
1 files changed, 2 insertions, 40 deletions
diff --git a/bin/zbatery b/bin/zbatery
index 619edcf..daa5c79 100755
--- a/bin/zbatery
+++ b/bin/zbatery
@@ -112,49 +112,11 @@ end
 config = ARGV[0] || "config.ru"
 abort "configuration file #{config} not found" unless File.exist?(config)
 
-if config =~ /\.ru$/
-  # parse embedded command-line options in config.ru comments
-  if File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) } =~ /^#\\(.*)/
-    opts.parse! $1.split(/\s+/)
-  end
-end
-
-require 'pp' if $DEBUG
-
-app = lambda do ||
-  # require Rack as late as possible in case $LOAD_PATH is modified
-  # in config.ru or command-line
-  inner_app = case config
-  when /\.ru$/
-    raw = File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) }
-    raw.sub!(/^__END__\n.*/, '')
-    eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config)
-  else
-    require config
-    Object.const_get(File.basename(config, '.rb').capitalize)
-  end
-  pp({ :inner_app => inner_app }) if $DEBUG
-  case ENV["RACK_ENV"]
-  when "development"
-    Rack::Builder.new do
-      use Rack::CommonLogger, $stderr
-      use Rack::ShowExceptions
-      use Rack::Lint
-      run inner_app
-    end.to_app
-  when "deployment"
-    Rack::Builder.new do
-      use Rack::CommonLogger, $stderr
-      run inner_app
-    end.to_app
-  else
-    inner_app
-  end
-end
-
+app = Unicorn.builder(config, opts)
 listeners << "#{host}:#{port}" if set_listener
 
 if $DEBUG
+  require 'pp'
   pp({
     :zbatery_options => options,
     :app => app,