Sha256: c23ebb90caf587d449b01390665a64d54147dd62355c04dfcdc6bbe5e035eb02

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

module Pageflow
  # Allow delegating to another Rack app from a controller action.
  #
  # @api private
  module ControllerDelegation
    # Abort currently executed controller action, call passed Rack app
    # and use its response instead. A block can be passed to mutate
    # the response.
    def delegate_to_rack_app!(app)
      result = app.call(request.env)
      yield(*result) if block_given?

      throw(:delegate, result)
    end

    # Override ActionController::Metal#dispatch [1] which returns the
    # Rack response triple generated by the controller. Calling
    # `delegate_to_rack_app!` aborts execution of the current
    # controller action and returns the response of the given Rack app
    # instead.
    #
    # The second argument passed to `throw` is becomes the return
    # value of `catch`. If `throw` is not called, `catch` passes the
    # return value of its block.
    #
    # [1] https://github.com/rails/rails/blob/8bec77cc0f1fd47677a331a64f68c5918efd2ca9/actionpack/lib/action_controller/metal.rb#L188
    def dispatch(*)
      catch(:delegate) { super }
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pageflow-17.0.4 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-17.0.3 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-17.0.2 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-17.0.1 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-17.0.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-16.2.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-16.1.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-16.0.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.8.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.7.1 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.7.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.6.1 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.6.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.5.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.4.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.3.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.2.2 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.2.1 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.2.0 app/controllers/concerns/pageflow/controller_delegation.rb
pageflow-15.1.2 app/controllers/concerns/pageflow/controller_delegation.rb