about summary refs log tree commit homepage
path: root/bin/unicorn
diff options
context:
space:
mode:
Diffstat (limited to 'bin/unicorn')
-rwxr-xr-xbin/unicorn17
1 files changed, 10 insertions, 7 deletions
diff --git a/bin/unicorn b/bin/unicorn
index da77198..6247f32 100755
--- a/bin/unicorn
+++ b/bin/unicorn
@@ -105,22 +105,25 @@ opts = OptionParser.new("", 24, '  ') do |opts|
   opts.parse! ARGV
 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
 
 # require Rack as late as possible in case $LOAD_PATH is modified
 # in config.ru or command-line
 require 'rack'
 
-config = ARGV[0] || "config.ru"
-abort "configuration file #{config} not found" unless File.exist?(config)
-
 inner_app = case config
 when /\.ru$/
   raw = File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) }
-  # parse embedded command-line options in config.ru comments
-  if raw[/^#\\(.*)/]
-    opts.parse! $1.split(/\s+/)
-  end
   lambda { || eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config) }
 else
   lambda do ||