Class: GrpcMock::GrpcStubAdapter
- Inherits:
-
Object
- Object
- GrpcMock::GrpcStubAdapter
- Defined in:
- lib/grpc_mock/grpc_stub_adapter.rb
Constant Summary collapse
- ADAPTER_CLASS =
To make hook point for GRCP::ClientStub github.com/grpc/grpc/blob/bec3b5ada2c5e5d782dff0b7b5018df646b65cb0/src/ruby/lib/grpc/generic/service.rb#L150-L186
Class.new(GRPC::ClientStub) do alias_method :original_request_response, :request_response alias_method :original_client_streamer, :client_streamer alias_method :original_server_streamer, :server_streamer alias_method :original_bidi_streamer, :bidi_streamer end
- HOOKED_CLASS =
Module.new do def request_response(method, req, marshal, unmarshal, **opt) if GrpcMock.config.allow_net_connect original_request_response(method, req, marshal, unmarshal, **opt) end end def client_streamer(method, requests, marshal, unmarshal, **opt) if GrpcMock.config.allow_net_connect original_client_streamer(method, requests, marshal, unmarshal, **opt) end end def server_streamer(method, req, marshal, unmarshal, **opt) if GrpcMock.config.allow_net_connect original_server_streamer(method, req, marshal, unmarshal, **opt) end end def bidi_streamer(method, requests, marshal, unmarshal, **opt) if GrpcMock.config.allow_net_connect original_bidi_streamer(method, requests, marshal, unmarshal, **opt) end end end
- THROUGHT_CLASS =
This class is only use for disabling grpc_stub_adapter hook
Module.new do def request_response(method, req, marshal, unmarshal, **opt) original_request_response(method, req, marshal, unmarshal, **opt) end def client_streamer(method, requests, marshal, unmarshal, **opt) original_client_streamer(method, requests, marshal, unmarshal, **opt) end def server_streamer(method, req, marshal, unmarshal, **opt) original_server_streamer(method, req, marshal, unmarshal, **opt) end def bidi_streamer(method, requests, marshal, unmarshal, **opt) original_bidi_streamer(method, requests, marshal, unmarshal, **opt) end end
Instance Method Summary collapse
Instance Method Details
#disable! ⇒ Object
66 67 68 69 |
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 66 def disable! clean_up ADAPTER_CLASS.prepend(THROUGHT_CLASS) end |
#enable! ⇒ Object
61 62 63 64 |
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 61 def enable! clean_up ADAPTER_CLASS.prepend(HOOKED_CLASS) end |