Class: Modern::Response

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/modern/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, body = [], status = 200, header = {}) ⇒ Response

Returns a new instance of Response.



12
13
14
15
16
17
# File 'lib/modern/response.rb', line 12

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

  @request = request
  @bypass = false
end

Instance Attribute Details

#bypassObject (readonly)

Returns the value of attribute bypass.



10
11
12
# File 'lib/modern/response.rb', line 10

def bypass
  @bypass
end

#requestObject (readonly)

Returns the value of attribute request.



9
10
11
# File 'lib/modern/response.rb', line 9

def request
  @request
end

Instance Method Details

#bypass!Object



19
20
21
# File 'lib/modern/response.rb', line 19

def bypass!
  @bypass = true
end

#json(object, pretty: false) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/modern/response.rb', line 23

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

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

#text(object) ⇒ Object



33
34
35
36
37
# File 'lib/modern/response.rb', line 33

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

  write(object.to_s)
end