Class: HttpStub::Server::Stub::Response::Response
- Inherits:
-
Object
- Object
- HttpStub::Server::Stub::Response::Response
- Defined in:
- lib/http_stub/server/stub/response/response.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#delay_in_seconds ⇒ Object
readonly
Returns the value of attribute delay_in_seconds.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(args) ⇒ Response
constructor
A new instance of Response.
- #serve_on(application) ⇒ Object
- #to_hash ⇒ Object
- #to_json(*args) ⇒ Object
- #with_values_from(request) ⇒ Object
Constructor Details
#initialize(args) ⇒ Response
Returns a new instance of Response.
14 15 16 17 18 19 20 21 22 |
# File 'lib/http_stub/server/stub/response/response.rb', line 14 def initialize(args) @original_args = args resolved_args = DEFAULT_ARGS.merge(args) @status = resolved_args[:status] @body = HttpStub::Server::Stub::Response::Body.create(resolved_args) @headers = HttpStub::Server::Stub::Response::Headers.create(resolved_args[:headers], @body) @delay_in_seconds = resolved_args[:delay_in_seconds] @blocks = HttpStub::Server::Stub::Response::Blocks.new(resolved_args[:blocks]) end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
12 13 14 |
# File 'lib/http_stub/server/stub/response/response.rb', line 12 def blocks @blocks end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/http_stub/server/stub/response/response.rb', line 12 def body @body end |
#delay_in_seconds ⇒ Object (readonly)
Returns the value of attribute delay_in_seconds.
12 13 14 |
# File 'lib/http_stub/server/stub/response/response.rb', line 12 def delay_in_seconds @delay_in_seconds end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/http_stub/server/stub/response/response.rb', line 12 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/http_stub/server/stub/response/response.rb', line 12 def status @status end |
Instance Method Details
#serve_on(application) ⇒ Object
28 29 30 31 |
# File 'lib/http_stub/server/stub/response/response.rb', line 28 def serve_on(application) sleep @delay_in_seconds @body.serve(application, self) end |
#to_hash ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/http_stub/server/stub/response/response.rb', line 33 def to_hash { status: @status, headers: @headers, body: @body, delay_in_seconds: @delay_in_seconds, blocks: @blocks.to_array } end |
#to_json(*args) ⇒ Object
43 44 45 |
# File 'lib/http_stub/server/stub/response/response.rb', line 43 def to_json(*args) self.to_hash.to_json(*args) end |
#with_values_from(request) ⇒ Object
24 25 26 |
# File 'lib/http_stub/server/stub/response/response.rb', line 24 def with_values_from(request) self.class.new(@original_args.merge(blocks: []).deep_merge(@blocks.evaluate_with(request))) end |