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
-
#match_rules ⇒ Object
readonly
Returns the value of attribute match_rules.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#stub_id ⇒ Object
readonly
Returns the value of attribute stub_id.
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Stub
constructor
A new instance of Stub.
- #matches?(criteria, logger) ⇒ Boolean
- #response_for(request) ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Stub
Returns a new instance of Stub.
9 10 11 12 13 14 15 16 |
# File 'lib/http_stub/server/stub/stub.rb', line 9 def initialize(hash) @stub_id = hash[:id] @uri = "/http_stub/stubs/#{@stub_id}" @match_rules = HttpStub::Server::Stub::Match::Rules.new(hash[:match_rules]) @response = HttpStub::Server::Stub::Response.create(hash[:response]) @triggers = HttpStub::Server::Stub::Triggers.new(hash[:triggers]) @description = hash.to_s end |
Instance Attribute Details
#match_rules ⇒ Object (readonly)
Returns the value of attribute match_rules.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def match_rules @match_rules 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_id ⇒ Object (readonly)
Returns the value of attribute stub_id.
7 8 9 |
# File 'lib/http_stub/server/stub/stub.rb', line 7 def stub_id @stub_id 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
18 19 20 |
# File 'lib/http_stub/server/stub/stub.rb', line 18 def matches?(criteria, logger) criteria.is_a?(String) ? criteria == @stub_id : @match_rules.matches?(criteria, logger) end |
#response_for(request) ⇒ Object
22 23 24 |
# File 'lib/http_stub/server/stub/stub.rb', line 22 def response_for(request) @response.with_values_from(request) end |
#to_json(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/http_stub/server/stub/stub.rb', line 26 def to_json(*args) { id: @stub_id, uri: @uri, match_rules: @match_rules, response: @response, triggers: @triggers }.to_json(*args) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/http_stub/server/stub/stub.rb', line 36 def to_s @description end |