Sha256: 0d7129f55b8562f7ec7df0e5fa22bebdd7654a1df7c55b6b7758f5964862b0c1

Contents?: true

Size: 689 Bytes

Versions: 6

Compression:

Stored size: 689 Bytes

Contents

# frozen_string_literal: true

require 'rack'

require 'json'

module Modern
  class Response < Rack::Response
    attr_reader :request
    attr_reader :bypass

    def initialize(request, body = [], status = 200, header = {})
      super(body, status, header)

      @request = request
      @bypass = false
    end

    def bypass!
      @bypass = true
    end

    def json(object, pretty: false)
      headers["Content-Type"] = "application/json"

      if pretty
        write(JSON.pretty_generate(object))
      else
        write(JSON.generate(object))
      end
    end

    def text(object)
      headers["Content-Type"] = "text/plain"

      write(object.to_s)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
modern-0.5.0 lib/modern/response.rb
modern-0.4.6 lib/modern/response.rb
modern-0.4.5 lib/modern/response.rb
modern-0.4.4 lib/modern/response.rb
modern-0.4.3 lib/modern/response.rb
modern-0.4.2 lib/modern/response.rb