Class: ProtoPharm::StubRegistry
- Inherits:
-
Object
- Object
- ProtoPharm::StubRegistry
- Defined in:
- lib/proto_pharm/stub_registry.rb
Instance Attribute Summary collapse
-
#request_stubs ⇒ Object
readonly
Returns the value of attribute request_stubs.
Instance Method Summary collapse
-
#all_requests_matching(path, request = nil) ⇒ Array<ProtoPharm::RequestStub>
Array of all matching request stubs, if any.
-
#find_request_matching(path, request) ⇒ ProtoPharm::RequestStub
RequestStub matching the given path/request, if found.
-
#initialize ⇒ StubRegistry
constructor
A new instance of StubRegistry.
- #register_request_stub(stub) ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ StubRegistry
Returns a new instance of StubRegistry.
7 8 9 |
# File 'lib/proto_pharm/stub_registry.rb', line 7 def initialize @request_stubs = {} end |
Instance Attribute Details
#request_stubs ⇒ Object (readonly)
Returns the value of attribute request_stubs.
5 6 7 |
# File 'lib/proto_pharm/stub_registry.rb', line 5 def request_stubs @request_stubs end |
Instance Method Details
#all_requests_matching(path, request = nil) ⇒ Array<ProtoPharm::RequestStub>
Returns Array of all matching request stubs, if any. See RequestPattern#match? for matching logic.
25 26 27 |
# File 'lib/proto_pharm/stub_registry.rb', line 25 def all_requests_matching(path, request = nil) request_stubs[path]&.select { |stub| stub.match?(path, request) } || [] end |
#find_request_matching(path, request) ⇒ ProtoPharm::RequestStub
Returns RequestStub matching the given path/request, if found.
32 33 34 |
# File 'lib/proto_pharm/stub_registry.rb', line 32 def find_request_matching(path, request) request_stubs[path]&.find { |stub| stub.match?(path, request) } end |
#register_request_stub(stub) ⇒ Object
16 17 18 19 20 |
# File 'lib/proto_pharm/stub_registry.rb', line 16 def register_request_stub(stub) request_stubs[stub.path] ||= [] request_stubs[stub.path].unshift(stub) stub end |
#reset! ⇒ Object
11 12 13 |
# File 'lib/proto_pharm/stub_registry.rb', line 11 def reset! @request_stubs = {} end |