Class: ActionDispatch::Callbacks

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Callbacks
Defined in:
actionpack/lib/action_dispatch/middleware/callbacks.rb

Overview

Provides callbacks to be executed before and after dispatching the request.

Constant Summary

Constants included from ActiveSupport::Callbacks

ActiveSupport::Callbacks::CALLBACK_FILTER_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupport::Callbacks

#run_callbacks

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included

Constructor Details

#initialize(app) ⇒ Callbacks

Returns a new instance of Callbacks.



20
21
22
# File 'actionpack/lib/action_dispatch/middleware/callbacks.rb', line 20

def initialize(app)
  @app = app
end

Class Method Details

.after(*args, &block) ⇒ Object



15
16
17
# File 'actionpack/lib/action_dispatch/middleware/callbacks.rb', line 15

def after(*args, &block)
  set_callback(:call, :after, *args, &block)
end

.before(*args, &block) ⇒ Object



11
12
13
# File 'actionpack/lib/action_dispatch/middleware/callbacks.rb', line 11

def before(*args, &block)
  set_callback(:call, :before, *args, &block)
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'actionpack/lib/action_dispatch/middleware/callbacks.rb', line 24

def call(env)
  error = nil
  result = run_callbacks :call do
    @app.call(env)
  rescue => error
  end
  raise error if error
  result
end