Module: Rack::Cargo::ResponseBuilder

Defined in:
lib/rack/cargo/response_builder.rb

Class Method Summary collapse

Class Method Details

.autogenerated_nameObject



20
21
22
# File 'lib/rack/cargo/response_builder.rb', line 20

def autogenerated_name
  "unnamed_#{SecureRandom.hex(6)}"
end

.call(request, state) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rack/cargo/response_builder.rb', line 7

def call(request, state)
  app_response = state.fetch(:app_response)

  name = request.fetch("name", autogenerated_name)

  state[:response] = {
    RESPONSE_NAME => name,
    RESPONSE_STATUS => app_response.fetch(:status),
    RESPONSE_HEADERS => app_response.fetch(:headers),
    RESPONSE_BODY => JSON.parse(app_response.fetch(:body).join)
  }
end