Module: GrpcMock::GrpcStubAdapter::Adapter
- Included in:
- GRPC::ClientStub
- Defined in:
- lib/grpc_mock/grpc_stub_adapter.rb
Overview
To make hook point for GRPC::ClientStub github.com/grpc/grpc/blob/bec3b5ada2c5e5d782dff0b7b5018df646b65cb0/src/ruby/lib/grpc/generic/service.rb#L150-L186
Instance Method Summary collapse
- #bidi_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
-
#client_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
TODO.
- #request_response(method, request, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
- #server_streamer(method, request, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
Instance Method Details
#bidi_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 86 def bidi_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs) unless GrpcMock::GrpcStubAdapter.enabled? return super end r = requests.to_a # FIXME: this may not work mock = GrpcMock.stub_registry.response_for_request(method, r) if mock if return_op operation = call.operation operation.define_singleton_method(:execute) do mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent end operation else mock.evaluate(r, nil) # FIXME: provide BidiCall equivalent end elsif GrpcMock.config.allow_net_connect super else raise NetConnectNotAllowedError, method end end |
#client_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
TODO
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 37 def client_streamer(method, requests, *args, metadata: {}, return_op: false, **kwargs) unless GrpcMock::GrpcStubAdapter.enabled? return super end r = requests.to_a # FIXME: this may not work mock = GrpcMock.stub_registry.response_for_request(method, r) if mock call = GrpcMock::MockedCall.new(metadata: ) if return_op operation = call.operation operation.define_singleton_method(:execute) do mock.evaluate(r, call.multi_req_view) end operation else mock.evaluate(r, call.multi_req_view) end elsif GrpcMock.config.allow_net_connect super else raise NetConnectNotAllowedError, method end end |
#request_response(method, request, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 12 def request_response(method, request, *args, metadata: {}, return_op: false, **kwargs) unless GrpcMock::GrpcStubAdapter.enabled? return super end mock = GrpcMock.stub_registry.response_for_request(method, request) if mock call = GrpcMock::MockedCall.new(metadata: ) if return_op operation = call.operation operation.define_singleton_method(:execute) do mock.evaluate(request, call.single_req_view) end operation else mock.evaluate(request, call.single_req_view) end elsif GrpcMock.config.allow_net_connect super else raise NetConnectNotAllowedError, method end end |
#server_streamer(method, request, *args, metadata: {}, return_op: false, **kwargs) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/grpc_mock/grpc_stub_adapter.rb', line 62 def server_streamer(method, request, *args, metadata: {}, return_op: false, **kwargs) unless GrpcMock::GrpcStubAdapter.enabled? return super end mock = GrpcMock.stub_registry.response_for_request(method, request) if mock call = GrpcMock::MockedCall.new(metadata: ) if return_op operation = call.operation operation.define_singleton_method(:execute) do mock.evaluate(request, call.single_req_view) end operation else mock.evaluate(request, call.single_req_view) end elsif GrpcMock.config.allow_net_connect super else raise NetConnectNotAllowedError, method end end |