2010-12-23 13:20:57 -05:00
|
|
|
|
2009-05-17 14:39:44 -04:00
|
|
|
module ActionDispatch
|
2014-11-22 23:22:36 -05:00
|
|
|
# Provides callbacks to be executed before and after dispatching the request.
|
2009-05-17 14:39:44 -04:00
|
|
|
class Callbacks
|
2009-10-12 23:15:43 -04:00
|
|
|
include ActiveSupport::Callbacks
|
2009-09-20 09:09:08 -04:00
|
|
|
|
2012-02-22 10:43:13 -05:00
|
|
|
define_callbacks :call
|
2009-09-20 09:09:08 -04:00
|
|
|
|
2010-12-23 13:20:57 -05:00
|
|
|
class << self
|
2016-02-21 20:25:52 -05:00
|
|
|
def to_prepare(*args, &block)
|
|
|
|
ActiveSupport::Reloader.to_prepare(*args, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_cleanup(*args, &block)
|
|
|
|
ActiveSupport::Reloader.to_complete(*args, &block)
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:51:43 -04:00
|
|
|
deprecate to_prepare: "use ActiveSupport::Reloader.to_prepare instead",
|
|
|
|
to_cleanup: "use ActiveSupport::Reloader.to_complete instead"
|
2009-09-20 09:09:08 -04:00
|
|
|
|
2013-11-14 13:53:35 -05:00
|
|
|
def before(*args, &block)
|
|
|
|
set_callback(:call, :before, *args, &block)
|
|
|
|
end
|
2009-09-20 09:09:08 -04:00
|
|
|
|
2013-11-14 13:53:35 -05:00
|
|
|
def after(*args, &block)
|
|
|
|
set_callback(:call, :after, *args, &block)
|
|
|
|
end
|
2009-09-20 09:09:08 -04:00
|
|
|
end
|
2009-05-17 14:39:44 -04:00
|
|
|
|
2011-05-24 17:38:59 -04:00
|
|
|
def initialize(app)
|
2010-12-19 18:58:58 -05:00
|
|
|
@app = app
|
2009-05-17 14:39:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2012-02-22 10:43:13 -05:00
|
|
|
error = nil
|
|
|
|
result = run_callbacks :call do
|
|
|
|
begin
|
|
|
|
@app.call(env)
|
|
|
|
rescue => error
|
|
|
|
end
|
2009-09-20 09:09:08 -04:00
|
|
|
end
|
2012-02-22 10:43:13 -05:00
|
|
|
raise error if error
|
|
|
|
result
|
2009-05-17 14:39:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|