Module: GrpcKit::GRPC::Dsl
- Defined in:
- lib/grpc_kit/grpc/dsl.rb
Instance Attribute Summary collapse
-
#marshal_class_method ⇒ Object
writeonly
Sets the attribute marshal_class_method.
-
#service_name ⇒ Object
writeonly
Sets the attribute service_name.
-
#unmarshal_class_method ⇒ Object
writeonly
Sets the attribute unmarshal_class_method.
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
- #rpc(name, marshal, unmarshal) ⇒ Object
- #rpc_descs ⇒ Object
- #rpc_stub_class ⇒ Object
- #stream(cls) ⇒ Object
Instance Attribute Details
#marshal_class_method=(value) ⇒ Object (writeonly)
Sets the attribute marshal_class_method
11 12 13 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 11 def marshal_class_method=(value) @marshal_class_method = value end |
#service_name=(value) ⇒ Object (writeonly)
Sets the attribute service_name
11 12 13 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 11 def service_name=(value) @service_name = value end |
#unmarshal_class_method=(value) ⇒ Object (writeonly)
Sets the attribute unmarshal_class_method
11 12 13 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 11 def unmarshal_class_method=(value) @unmarshal_class_method = value end |
Instance Method Details
#inherited(subclass) ⇒ Object
13 14 15 16 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 13 def inherited(subclass) subclass.rpc_descs.merge!(rpc_descs) subclass.service_name = @service_name end |
#rpc(name, marshal, unmarshal) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 18 def rpc(name, marshal, unmarshal) if rpc_descs.key?(name) raise "rpc (#{name}) is already defined" end unless marshal.respond_to?(@marshal_class_method) raise "#{marshal} must implement #{marshal}.#{@marshal_class_method}" end unless unmarshal.respond_to?(@unmarshal_class_method) raise "#{unmarshal} must implement #{unmarshal}.#{@unmarshal_class_method}" end rpc_desc = GrpcKit::RpcDesc.new( name: name, marshal: marshal, unmarshal: unmarshal, marshal_method: @marshal_class_method, unmarshal_method: @unmarshal_class_method, service_name: @service_name, ) rpc_descs[rpc_desc.path] = rpc_desc define_method(rpc_desc.ruby_style_name) do |_, _| raise GrpcKit::Errors::Unimplemented, name.to_s end end |
#rpc_descs ⇒ Object
80 81 82 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 80 def rpc_descs @rpc_descs ||= {} end |
#rpc_stub_class ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 50 def rpc_stub_class rpc_descs_ = rpc_descs Class.new(GrpcKit::Client) do rpc_descs_.each do |_, rpc_desc| method_name = rpc_desc.ruby_style_name rpc = rpc_desc.build_client if rpc_desc.request_response? define_method(method_name) do |request, opts = {}| request_response(rpc, request, opts) end elsif rpc_desc.client_streamer? define_method(method_name) do |opts = {}| client_streamer(rpc, opts) end elsif rpc_desc.server_streamer? define_method(method_name) do |request, opts = {}| server_streamer(rpc, request, opts) end elsif rpc_desc.bidi_streamer? define_method(method_name) do |requests, opts = {}, &blk| bidi_streamer(rpc, requests, opts, &blk) end else raise "unknown #{rpc_desc}" end end end end |
#stream(cls) ⇒ Object
46 47 48 |
# File 'lib/grpc_kit/grpc/dsl.rb', line 46 def stream(cls) GrpcKit::GRPC::Stream.new(cls) end |