class Rack::BodySerializer

Constants

ACCEPT_KEY
HEADER_KEY
VERSION

Attributes

mapping[R]

Public Class Methods

new(stack, mapping, default) click to toggle source
# File lib/rack/body_serializer.rb, line 10
def initialize(stack, mapping, default)
  @stack = stack
  @mapping = mapping
  @default = default
end

Public Instance Methods

call(previous_state) click to toggle source
# File lib/rack/body_serializer.rb, line 16
def call(previous_state)
  @state = previous_state
  @status, @headers, @body = @stack.call(state)

  if accept_type && body.size > 0
    @body = serializer.dump(body)
    headers[HEADER_KEY] = mapping.key(serializer)
  end

  [status, headers, body]
end

Private Instance Methods

accept_type() click to toggle source
# File lib/rack/body_serializer.rb, line 28
        def accept_type
  state[ACCEPT_KEY]
end
body() click to toggle source
# File lib/rack/body_serializer.rb, line 52
        def body
  @body
end
headers() click to toggle source
# File lib/rack/body_serializer.rb, line 44
        def headers
  @headers
end
serializer() click to toggle source
# File lib/rack/body_serializer.rb, line 32
        def serializer
  mapping[accept_type] || @default
end
stack() click to toggle source
# File lib/rack/body_serializer.rb, line 36
        def stack
  @stack
end
state() click to toggle source
# File lib/rack/body_serializer.rb, line 40
        def state
  @state
end
status() click to toggle source
# File lib/rack/body_serializer.rb, line 48
        def status
  @status
end