Class: HttpStub::Server::Stub::Response::TextBody
- Inherits:
-
Object
- Object
- HttpStub::Server::Stub::Response::TextBody
- Defined in:
- lib/http_stub/server/stub/response/text_body.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ TextBody
constructor
A new instance of TextBody.
- #serve(application, response) ⇒ Object
- #to_s ⇒ Object
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
#headers ⇒ Object (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 |
#text ⇒ Object (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_s ⇒ Object
23 24 25 |
# File 'lib/http_stub/server/stub/response/text_body.rb', line 23 def to_s @text end |