Class: ActionDispatch::Callbacks

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

Overview

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Callbacks

Returns a new instance of Callbacks.



30
31
32
# File 'lib/action_dispatch/middleware/callbacks.rb', line 30

def initialize(app)
  @app = app
end

Class Method Details

.after(*args, &block) ⇒ Object



25
26
27
# File 'lib/action_dispatch/middleware/callbacks.rb', line 25

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

.before(*args, &block) ⇒ Object



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

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

.to_cleanup(*args, &block) ⇒ Object



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

def to_cleanup(*args, &block)
  ActiveSupport::Reloader.to_complete(*args, &block)
end

.to_prepare(*args, &block) ⇒ Object



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

def to_prepare(*args, &block)
  ActiveSupport::Reloader.to_prepare(*args, &block)
end

Instance Method Details

#call(env) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/action_dispatch/middleware/callbacks.rb', line 34

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