Class: HttpStub::Server::StubResponse::Base
- Inherits:
-
Object
- Object
- HttpStub::Server::StubResponse::Base
- Defined in:
- lib/http_stub/server/stub_response/base.rb
Instance Attribute Summary collapse
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(args = {}) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Base
Returns a new instance of Base.
37 38 39 40 41 42 43 44 |
# File 'lib/http_stub/server/stub_response/base.rb', line 37 def initialize(args={}) @original_args = args resolved_args = self.class.merge_defaults(args) @status = resolved_args["status"] @body = resolved_args["body"] @delay_in_seconds = resolved_args["delay_in_seconds"] @headers = HttpStub::Server::Headers.new(resolved_args["headers"]) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
35 36 37 |
# File 'lib/http_stub/server/stub_response/base.rb', line 35 def body @body end |
#delay_in_seconds ⇒ Object (readonly)
Returns the value of attribute delay_in_seconds.
35 36 37 |
# File 'lib/http_stub/server/stub_response/base.rb', line 35 def delay_in_seconds @delay_in_seconds end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
35 36 37 |
# File 'lib/http_stub/server/stub_response/base.rb', line 35 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
35 36 37 |
# File 'lib/http_stub/server/stub_response/base.rb', line 35 def status @status end |
Class Method Details
.add_default_headers(headers) ⇒ Object
15 16 17 |
# File 'lib/http_stub/server/stub_response/base.rb', line 15 def add_default_headers(headers) default_headers.merge!(headers) end |
.merge_defaults(args) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/http_stub/server/stub_response/base.rb', line 19 def merge_defaults(args) args.clone.tap do |result| headers = result["headers"] ||= {} DEFAULT_ARGS.each { |key, value| result[key] = value if !result[key] || result[key] == "" } default_headers.each { |key, value| headers[key] = value if !headers[key] || headers[key] == "" } end end |
Instance Method Details
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/http_stub/server/stub_response/base.rb', line 46 def empty? @original_args.empty? end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/http_stub/server/stub_response/base.rb', line 50 def to_s @original_args.to_s end |