2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
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
|