1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch/middleware/callbacks.rb
Ryuta Kamizono 892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00

34 lines
668 B
Ruby

# frozen_string_literal: true
module ActionDispatch
# Provides callbacks to be executed before and after dispatching the request.
class Callbacks
include ActiveSupport::Callbacks
define_callbacks :call
class << self
def before(*args, &block)
set_callback(:call, :before, *args, &block)
end
def after(*args, &block)
set_callback(:call, :after, *args, &block)
end
end
def initialize(app)
@app = app
end
def call(env)
error = nil
result = run_callbacks :call do
@app.call(env)
rescue => error
end
raise error if error
result
end
end
end