Class: HttpStub::Server::Stub::Stub
- Inherits:
-
Object
- Object
- HttpStub::Server::Stub::Stub
- Defined in:
- lib/http_stub/server/stub/stub.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#stub_uri ⇒ Object
readonly
Returns the value of attribute stub_uri.
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(args) ⇒ Stub
constructor
A new instance of Stub.
- #matches?(criteria, logger) ⇒ Boolean
- #response_for(request) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Stub
Returns a new instance of Stub.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/http_stub/server/stub/stub.rb', line 9 def initialize(args) @id = args["id"] || SecureRandom.uuid @uri = HttpStub::Server::Stub::Match::Rule::Uri.new(args["uri"]) @method = HttpStub::Server::Stub::Match::Rule::Method.new(args["method"]) @headers = HttpStub::Server::Stub::Match::Rule::Headers.new(args["headers"]) @parameters = HttpStub::Server::Stub::Match::Rule::Parameters.new(args["parameters"]) @body = HttpStub::Server::Stub::Match::Rule::Body.create(args["body"]) @response = HttpStub::Server::Stub::Response.create(args["response"]) @triggers = HttpStub::Server::Stub::Triggers.new(args["triggers"]) @stub_uri = "/http_stub/stubs/#{@id}" @description = args.to_s end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def method @method end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def parameters @parameters end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def response @response end |
#stub_uri ⇒ Object (readonly)
Returns the value of attribute stub_uri.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def stub_uri @stub_uri end |
#triggers ⇒ Object (readonly)
Returns the value of attribute triggers.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def triggers @triggers end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def uri @uri end |
Instance Method Details
#matches?(criteria, logger) ⇒ Boolean
22 23 24 |
# File 'lib/http_stub/server/stub/stub.rb', line 22 def matches?(criteria, logger) criteria.is_a?(String) ? matches_by_id?(criteria) : matches_by_rules?(criteria, logger) end |
#response_for(request) ⇒ Object
26 27 28 |
# File 'lib/http_stub/server/stub/stub.rb', line 26 def response_for(request) @response.with_values_from(request) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/http_stub/server/stub/stub.rb', line 30 def to_s @description end |