Class: HttpStub::Server::Stub::Response::TextBody

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/server/stub/response/text_body.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ TextBody

Returns a new instance of TextBody.



14
15
16
17
# File 'lib/http_stub/server/stub/response/text_body.rb', line 14

def initialize(args={})
  @headers = args[:json] ? JSON_HEADERS : {}
  @text    = args[:json].try(:to_json) || args[:body] || ""
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



12
13
14
# File 'lib/http_stub/server/stub/response/text_body.rb', line 12

def headers
  @headers
end

#textObject (readonly)

Returns the value of attribute text.



12
13
14
# File 'lib/http_stub/server/stub/response/text_body.rb', line 12

def text
  @text
end

Instance Method Details

#serve(application, response) ⇒ Object



19
20
21
# File 'lib/http_stub/server/stub/response/text_body.rb', line 19

def serve(application, response)
  application.halt(response.status, response.headers, @text)
end

#to_sObject



23
24
25
# File 'lib/http_stub/server/stub/response/text_body.rb', line 23

def to_s
  @text
end