From 264e912a028a95481969ca407cf0a4ed36e9b95c Mon Sep 17 00:00:00 2001 From: Samuel Cochran Date: Mon, 18 Nov 2013 10:59:11 +1100 Subject: [PATCH] Refine the no-exit implementaton a little --- lib/mail_catcher.rb | 16 ++++++++++++---- lib/mail_catcher/web.rb | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/mail_catcher.rb b/lib/mail_catcher.rb index 71bec83..9e78f15 100644 --- a/lib/mail_catcher.rb +++ b/lib/mail_catcher.rb @@ -55,13 +55,17 @@ module MailCatcher extend self :daemon => !windows?, :growl => growlnotify?, :browse => false, - :no_exit => false, + :quit => true, } def options @@options end + def quittable? + options[:quit] + end + def parse! arguments=ARGV, defaults=@defaults @@defaults.dup.tap do |options| OptionParser.new do |parser| @@ -88,8 +92,8 @@ module MailCatcher extend self options[:http_port] = port end - parser.on("--no-exit", "Can't exit from the application'") do - options[:no_exit] = true + parser.on("--no-quit", "Don't allow quitting the process") do + options[:quit] = false end if mac? @@ -173,7 +177,11 @@ module MailCatcher extend self # Daemonize, if we should, but only after the servers have started. if options[:daemon] EventMachine.next_tick do - puts "*** MailCatcher runs as a daemon by default. Go to the web interface to quit." + if quittable? + puts "*** MailCatcher runs as a daemon by default. Go to the web interface to quit." + else + puts "*** MailCatcher is now running as a daemon that cannot be quit." + end Process.daemon end end diff --git a/lib/mail_catcher/web.rb b/lib/mail_catcher/web.rb index ee65906..670b509 100644 --- a/lib/mail_catcher/web.rb +++ b/lib/mail_catcher/web.rb @@ -18,9 +18,11 @@ class MailCatcher::Web < Sinatra::Base end delete '/' do - unless MailCatcher.options[:no_exit] + if MailCatcher.quittable? MailCatcher.quit! status 204 + else + status 403 end end