Permalink
Browse files

Make it possible to disable server startup in the at_exit block

  • Loading branch information...
1 parent a6f5299 commit 507375f80b6e63b73625d327ac32b2d5ed9acc68 @moretea moretea committed Nov 15, 2012
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/goliath/application.rb
View
15 lib/goliath/application.rb
@@ -24,6 +24,15 @@ module Application
module_function
+ # Control wheter or not the application will be run using an at_exit block.
+ class << self
+ attr_accessor :run_app_on_exit
+ alias_method :run_app_on_exit?, :run_app_on_exit
+ end
+
+ # By default, we do run the application using the at_exit block.
+ self.run_app_on_exit = true
+
# Like Kernel#caller but excluding certain magic entries and without
# line / method information; the resulting array contains filenames only.
def caller_files
@@ -125,7 +134,11 @@ def camel_case(str)
end
at_exit do
- if $!.nil? && $0 == Goliath::Application.app_file
+ # Only run the application if ...
+ # - we want it to run
+ # - there has been no exception raised
+ # - the file that has been run, is the goliath application file
+ if Goliath::Application.run_app_on_exit? && $!.nil? && $0 == Goliath::Application.app_file
Application.run!
end
end

0 comments on commit 507375f

Please sign in to comment.