class GraphqlGrpc::TypeLibrary
Public Class Methods
descriptor_for(klass_str)
click to toggle source
generated_klass - a class created by the 'proto' compiler; maps to a Descriptor in the generated pool.
# File lib/graphql_grpc/type_library.rb, line 183 def self.descriptor_for(klass_str) klass_str = klass_str.to_s # If given a ruby class reference, convert to "java package" string # Pull the Google::Protobuf::Descriptor out of the pool and return it # with the name Google::Protobuf::DescriptorPool.generated_pool.lookup( ruby_class_to_underscore(klass_str) ) || Google::Protobuf::DescriptorPool.generated_pool.lookup( ruby_class_to_dotted(klass_str) ) end
new(top_level_types)
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 151 def initialize(top_level_types) build_descriptors(top_level_types) end
ruby_class_to_dotted(klass_str)
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 207 def self.ruby_class_to_dotted(klass_str) klass_str.gsub('::', '.') end
ruby_class_to_underscore(klass_str)
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 195 def self.ruby_class_to_underscore(klass_str) if klass_str.to_s.include?('::') java_name = klass_str.to_s.split('::') camel_case = java_name.pop java_package = java_name.map(&:underscore) # Put the name back together (java_package + [camel_case]).join('.') else klass_str end end
Public Instance Methods
build_descriptors(some_types)
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 155 def build_descriptors(some_types) # Keep track of known types to avoid infinite loops when there # are circular dependencies between gRPC types @descriptors ||= {} some_types.each do |java_class_name| next unless @descriptors[java_class_name].nil? # Store a reference to this type descriptor = descriptor_for(java_class_name) @descriptors[java_class_name] ||= descriptor # Recurse build_descriptors(descriptor.sub_types) if descriptor.respond_to?(:sub_types) # Some types aren't found from #sub_types; iterate #entries of # type :message to get those. if descriptor.respond_to?(:entries) build_descriptors( descriptor.entries .select { |e| e.try(:type) == :message } .map(&:submsg_name) .uniq ) end end end
descriptor_for(klass_str)
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 211 def descriptor_for(klass_str) TypeLibrary.descriptor_for(klass_str) end
to_schema_types()
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 223 def to_schema_types @descriptors.values.compact.map do |t| t.to_gql_type(type_prefix) end.sort.uniq.join("\n") end
type_prefix()
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 219 def type_prefix '' end
types()
click to toggle source
# File lib/graphql_grpc/type_library.rb, line 215 def types @descriptors end