Module: ProtoPharm::GrpcStubAdapter::MockStub
- Defined in:
- lib/proto_pharm/grpc_stub_adapter/mock_stub.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bidi_streamer(method, requests, *args) ⇒ Object
-
#client_streamer(method, requests, *args) ⇒ Object
TODO.
- #request_response(method, request, *args, return_op: false, **opts) ⇒ Object
- #server_streamer(method, request, *args) ⇒ Object
Class Method Details
.allow_net_connect! ⇒ Object
11 12 13 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 11 def allow_net_connect! @allow_net_connect = true end |
.allow_net_connect? ⇒ Boolean
15 16 17 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 15 def allow_net_connect? @allow_net_connect || false end |
.disable_net_connect! ⇒ Object
7 8 9 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 7 def disable_net_connect! @allow_net_connect = false end |
Instance Method Details
#bidi_streamer(method, requests, *args) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 71 def bidi_streamer(method, requests, *args) return super unless ProtoPharm.enabled? r = requests.to_a # FIXME: this may not work request_stub = ProtoPharm.stub_registry.find_request_matching(method, r) if request_stub request_stub.received!(requests) request_stub.response.evaluate elsif _allow_net_connect? super else raise NetConnectNotAllowedError, method end end |
#client_streamer(method, requests, *args) ⇒ Object
TODO
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 40 def client_streamer(method, requests, *args) return super unless ProtoPharm.enabled? r = requests.to_a # FIXME: this may not work request_stub = ProtoPharm.stub_registry.find_request_matching(method, r) if request_stub request_stub.received!(requests) request_stub.response.evaluate elsif _allow_net_connect? super else raise NetConnectNotAllowedError, method end end |
#request_response(method, request, *args, return_op: false, **opts) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 20 def request_response(method, request, *args, return_op: false, **opts) return super unless ProtoPharm.enabled? request_stub = ProtoPharm.stub_registry.find_request_matching(method, request) if request_stub operation = OperationStub.new(metadata: opts[:metadata]) do request_stub.received!(request) request_stub.response.evaluate(request) end return_op ? operation : operation.execute elsif _allow_net_connect? super else raise NetConnectNotAllowedError, method end end |
#server_streamer(method, request, *args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/proto_pharm/grpc_stub_adapter/mock_stub.rb', line 56 def server_streamer(method, request, *args) return super unless ProtoPharm.enabled? request_stub = ProtoPharm.stub_registry.find_request_matching(method, request) if request_stub request_stub.received!(request) request_stub.response.evaluate elsif _allow_net_connect? super else raise NetConnectNotAllowedError, method end end |