summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-28 19:20:11 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-28 19:20:11 -0800
commita4a8bf7604d1c15c5a8fb9cb6be37e8bccb32e52 (patch)
tree56486ea2e59414f4a4e97109309ed69e7dec7cdb
parent947b8e5d312446b63a7dbd5be51a1bebf421cea8 (diff)
Do not assume the user wants config.ru to be Encoding::BINARY
for 1.9.
-rwxr-xr-xbin/unicorn_rails9
-rw-r--r--lib/unicorn.rb6
2 files changed, 5 insertions, 10 deletions
diff --git a/bin/unicorn_rails b/bin/unicorn_rails
index a27e9df..4406a34 100755
--- a/bin/unicorn_rails
+++ b/bin/unicorn_rails
@@ -110,15 +110,11 @@ end
 
 config = ARGV[0] || (File.exist?('config.ru') ? 'config.ru' : nil)
 
-if config && config =~ /\.ru$/
+if config && config =~ /\.ru\z/
   # 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
+  /^#\\(.*)/ =~ File.read(config) and opts.parse!($1.split(/\s+/))
 end
 
-require 'pp' if $DEBUG
-
 def rails_builder(config, daemonize)
   # this lambda won't run until after forking if preload_app is false
   lambda do ||
@@ -185,6 +181,7 @@ def rails_builder(config, daemonize)
 end
 
 app = rails_builder(config, daemonize)
+require 'pp' if $DEBUG
 
 listeners << "#{host}:#{port}" if set_listener
 
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 43ef9e8..8c0ff6e 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -35,15 +35,13 @@ module Unicorn
     def builder(ru, opts)
       if ru =~ /\.ru\z/
         # parse embedded command-line options in config.ru comments
-        if File.open(ru, "rb") { |fp| fp.sysread(fp.stat.size) } =~ /^#\\(.*)/
-          opts.parse! $1.split(/\s+/)
-        end
+        /^#\\(.*)/ =~ File.read(ru) and opts.parse!($1.split(/\s+/))
       end
 
       lambda do ||
         inner_app = case ru
         when /\.ru$/
-          raw = File.open(ru, "rb") { |fp| fp.sysread(fp.stat.size) }
+          raw = File.read(ru)
           raw.sub!(/^__END__\n.*/, '')
           eval("Rack::Builder.new {(#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru)
         else