Class: ProtoPharm::Introspection::RpcInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/proto_pharm/introspection/rpc_inspector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, endpoint_name) ⇒ RpcInspector

Returns a new instance of RpcInspector.



10
11
12
13
14
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 10

def initialize(service, endpoint_name)
  @grpc_service = ServiceResolver.resolve(service)

  @endpoint_name = endpoint_name
end

Instance Attribute Details

#endpoint_nameObject (readonly)

Returns the value of attribute endpoint_name.



6
7
8
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 6

def endpoint_name
  @endpoint_name
end

#grpc_serviceObject (readonly)

Returns the value of attribute grpc_service.



6
7
8
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 6

def grpc_service
  @grpc_service
end

Instance Method Details

#grpc_pathObject



34
35
36
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 34

def grpc_path
  @grpc_path ||= "/#{service_name}/#{normalized_rpc_name}"
end

#input_typeObject



38
39
40
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 38

def input_type
  rpc_desc.input
end

#normalize_request_proto(proto = nil, **kwargs) ⇒ Object



16
17
18
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 16

def normalize_request_proto(proto = nil, **kwargs)
  cast_proto(input_type, proto, **kwargs)
end

#normalize_response_proto(proto = nil, **kwargs) ⇒ Object



20
21
22
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 20

def normalize_response_proto(proto = nil, **kwargs)
  cast_proto(output_type, proto, **kwargs)
end

#normalized_rpc_nameObject



24
25
26
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 24

def normalized_rpc_name
  @normalized_rpc_name ||= endpoint_name.to_s.camelize.to_sym
end

#output_typeObject



42
43
44
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 42

def output_type
  rpc_desc.output
end

#rpc_descObject



28
29
30
31
32
# File 'lib/proto_pharm/introspection/rpc_inspector.rb', line 28

def rpc_desc
  @rpc_desc ||= rpc_descs[normalized_rpc_name].tap do |endpoint|
    raise RpcNotFoundError, "Service #{service_name} does not implement '#{normalized_rpc_name}'" if endpoint.blank?
  end
end