Sha256: 6c194f4a61817360f2dd083fa8ccc4e038ddf4cfe035326696a74fae001c7d0d

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

module Esplanade
  class Response
    class Body < Hash
      class << self
        private_class_method :new

        def craft(body)
          # According to specification Rack http://rack.github.io
          # body can only answer each
          lines = []
          body.each { |line| lines.push(line) }
          lines_to_json(lines)
        end

        private

        def lines_to_json(lines)
          if lines.join.empty?
            {}
          else
            res = lines.join('\n')
            begin
              MultiJson.load(res)
            rescue MultiJson::ParseError
              res
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
esplanade-0.1.0 lib/esplanade/response/body.rb