same code, a little organization
@@ -51,13 +51,13 @@ EOS
return ::Rack::Builder.parse_file filename
end
- def call
- if ARGV[0] =~ /(\-\?)|(help)|(\?)|(h)|(\-h)$/
- return print_help
+ def filename_argument
+ return ((ARGV[-2].to_s[0] != '-' || ARGV[-2].to_s == '-warmup' || ARGV[-2].to_s == '-v' || ARGV[-2].to_s == '-q' || (ARGV[-2].to_s[0] == '-' && ARGV[-2].to_i.to_s == ARGV[-2].to_s)) && ARGV[-1].to_s[0] != '-' && ARGV[-1])
end
+ def get_app_opts
app, opt = nil, nil
- filename = ((ARGV[-2].to_s[0] != '-' || ARGV[-2].to_s == '-warmup' || ARGV[-2].to_s == '-v' || ARGV[-2].to_s == '-q' || (ARGV[-2].to_s[0] == '-' && ARGV[-2].to_i.to_s == ARGV[-2].to_s)) && ARGV[-1].to_s[0] != '-' && ARGV[-1])
+ filename = filename_argument
if filename
app, opt = try_file filename;
unless opt
@@ -70,17 +70,19 @@ EOS
unless opt
puts "WARNING: Ruby application not found#{ filename ? " - missing both #{filename} and config.ru" : " - missing config.ru"}."
- if ARGV.index('-www') && ARGV[ARGV.index('-www') + 1]
+ if Iodine::DEFAULT_HTTP_ARGS[:public]
puts " Running only static file service."
opt = ::Rack::Server::Options.new.parse!([])
else
puts "For help run:"
puts " iodine -?"
- return
+ exit(0);
end
end
+ return app, opt
+ end
- if ARGV.index('-warmup')
+ def perform_warmup
# load anything marked with `autoload`, since autoload isn't thread safe nor fork friendly.
Iodine.run do
Module.constants.each do |n|
@@ -97,6 +99,16 @@ EOS
end
end
end
+
+ def call
+ if ARGV[0] =~ /(\-\?)|(help)|(\?)|(h)|(\-h)$/
+ return print_help
+ end
+
+ app, opt = get_app_opts
+
+ perform_warmup if ARGV.index('-warmup')
+
Iodine::Rack.run(app, opt)
end
