class ProtoPharm::StubRegistry

Attributes

request_stubs[R]

Public Class Methods

new() click to toggle source
# File lib/proto_pharm/stub_registry.rb, line 7
def initialize
  @request_stubs = {}
end

Public Instance Methods

all_requests_matching(path, request = nil) click to toggle source

@param path [String] @param request [Object] Optional; specify a request object to match against. Default: nil. @return [Array<ProtoPharm::RequestStub>] Array of all matching request stubs, if any. See {RequestPattern#match?} for matching logic.

# 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) click to toggle source

@param path [String] @param request [Object] @return [ProtoPharm::RequestStub] RequestStub matching the given path/request, if found

# 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) click to toggle source

@param stub [ProtoPharm::RequestStub]

# 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!() click to toggle source
# File lib/proto_pharm/stub_registry.rb, line 11
def reset!
  @request_stubs = {}
end