Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make it possible to disable server startup in the at_exit block #217

Merged
merged 2 commits into from

4 participants

@moretea

This hook is executed after any program that load Goliath::Application.

It made my sprockets-for-goliath gem specs to fail (see failed travis build).

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.
@igrigorik Owner

Spelling mistake in "whether", but otherwise, lgtm. :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dj2
Owner

Not sure if we want this. If you're including the Application then you want it to auto-run. I think the correct solution would be to not require goliath/goliath in your spec. If it's specific things you need, require those bits directly.

Not pulling goliath::Application into your spec would solve the issue I think.

@moretea

@dj2 I'm afraid that your suggestion doesn't work.

My gem depends on Goliath::API, which does a require "goliath/goliath" here, so goliath/application.rb get's loaded whether I want it or not.

@moretea

If you guys have any suggestions about how to fix this in another way: I'm open for alternatives.

@igrigorik
Owner

Seems to make sense to me. @dj2? :)

@rubencaro

I would find this useful too for testing.

@igrigorik igrigorik merged commit fc2e630 into postrank-labs:master

1 check passed

Details default The Travis build passed
@igrigorik
Owner

Merged - thanks! @dj2 if you have a better way.. we can revert. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2012
  1. @moretea
Commits on Nov 16, 2012
  1. @moretea

    Fix typo

    moretea authored
This page is out of date. Refresh to see the latest.
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 whether 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
Something went wrong with that request. Please try again.