Class: AgileProxy::Response
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AgileProxy::Response
- Defined in:
- lib/agile_proxy/model/response.rb
Overview
The associated response for the RequestSpec
An instance of this class is expected to be stored alongside every RequestSpec.
It is responsible for the following :-
-
Retrieving response
-
Persisting responses
-
Providing a ‘rack’ ouput of the response
-
Convenient setters for code, body and content_type
-
Template parsing
Constant Summary collapse
- PROTECTED_HEADERS =
['Content-Type']
Instance Method Summary collapse
-
#content_type=(val) ⇒ Object
A convenient setter for the content_type within the header.
-
#to_rack(input_params, _input_headers, _input_body) ⇒ Array
Provides the response as a ‘rack’ response.
Instance Method Details
#content_type=(val) ⇒ Object
A convenient setter for the content_type within the header
22 23 24 25 26 |
# File 'lib/agile_proxy/model/response.rb', line 22 def content_type=(val) write_attribute(:content_type, val) headers.merge!('Content-Type' => val) val end |
#to_rack(input_params, _input_headers, _input_body) ⇒ Array
Provides the response as a ‘rack’ response
If the response is a template (by specifying is_template as true), the output will have its template values parsed and replaced with data from the input_params, input_headers and input_body Otherwise, the body of the output is sent as is.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/agile_proxy/model/response.rb', line 37 def to_rack(input_params, _input_headers, _input_body) output_headers = headers.clone output_headers.merge! 'Cache-Control' => 'no-store' output_content = content output_status_code = status_code if is_template data = OpenStruct.new input_params template = Tilt['handlebars'].new { output_content } output_content = template.render data end EventMachine::Synchrony.sleep(delay) if delay > 0 [output_status_code, output_headers, [output_content]] end |