Sha256: 9a27b87cc2cb2bcda63bb0f31666b3f0385468ea1bce95cf72b63e1f7794e9a6

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

class Rack::App::Endpoint::Executor

  def initialize(endpoint_properties)
    @endpoint_properties = endpoint_properties
    @endpoint_properties.endpoint_method_name
  end

  def call(env)
    return catch(:rack_response){ execute(env) }.finish
  end

  protected

  def execute(env)
    request_handler = env[Rack::App::Constants::ENV::REQUEST_HANDLER]
    set_response_body(request_handler, get_response_body(request_handler))
    return request_handler.response
  end

  def get_response_body(request_handler)
    catch :response_body do
      evaluated_value = evaluate_value(request_handler)

      evaluated_value
    end
  end

  EXTNAME = ::Rack::App::Constants::ENV::EXTNAME

  def set_response_body(handler, response_body)
    extname = handler.request.env[EXTNAME]
    handler.response.headers.merge!(@endpoint_properties.serializer.response_headers_for(extname))
    handler.response.write(@endpoint_properties.serializer.serialize(extname, response_body))
  end

  def evaluate_value(request_handler)
    @endpoint_properties.error_handler.execute_with_error_handling_for(request_handler) do
      request_handler.__send__(@endpoint_properties.endpoint_method_name)
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rack-app-5.12.0 lib/rack/app/endpoint/executor.rb
rack-app-5.11.1 lib/rack/app/endpoint/executor.rb
rack-app-5.11.0 lib/rack/app/endpoint/executor.rb
rack-app-5.10.2 lib/rack/app/endpoint/executor.rb
rack-app-5.10.1 lib/rack/app/endpoint/executor.rb
rack-app-5.10.0 lib/rack/app/endpoint/executor.rb
rack-app-5.9.0 lib/rack/app/endpoint/executor.rb
rack-app-5.8.0 lib/rack/app/endpoint/executor.rb
rack-app-5.7.0 lib/rack/app/endpoint/executor.rb
rack-app-5.7.0.rc lib/rack/app/endpoint/executor.rb