Module: ElasticGraph::ProtoIngestion::SchemaDefinition::SchemaElements::ObjectInterfaceAndUnionExtension
- Defined in:
- elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb
Overview
Extends object/interface/union types with proto field type conversion.
Class Method Summary collapse
-
.list_depth_and_base_type(type_ref) ⇒ Array
Returns a type reference's list depth and fully unwrapped base type.
Instance Method Summary collapse
-
#proto_ingestion_metadata ⇒ RuntimeMetadata::Type
Returns metadata for fields whose index name differs from their public name, or whose scalar has ingestion rules beyond its protobuf wire type.
-
#proto_name ⇒ String
Returns this type's name in protobuf schemas.
-
#proto_type_reference(package_name) ⇒ String
Returns the fully qualified name used to reference this message from protobuf fields.
-
#protobuf_field_comment ⇒ nil
Messages carry their documentation on the message definition itself, so fields of this type get no format comment.
-
#protobuf_import ⇒ nil
Messages render their own protobuf definition, so they never require an import.
-
#referenced_proto_types ⇒ Array
Returns the schema types referenced by this definition.
-
#to_proto(schema, package_name) ⇒ String
Renders this type's protobuf message definition.
Class Method Details
.list_depth_and_base_type(type_ref) ⇒ Array
Returns a type reference's list depth and fully unwrapped base type.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 44 def self.list_depth_and_base_type(type_ref) list_depth = 0 current = type_ref.unwrap_non_null while current.list? list_depth += 1 current = current.unwrap_list.unwrap_non_null end [list_depth, current] end |
Instance Method Details
#proto_ingestion_metadata ⇒ RuntimeMetadata::Type
Returns metadata for fields whose index name differs from their public name, or whose scalar has ingestion rules beyond its protobuf wire type. Abstract types have no fields.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 60 def return RuntimeMetadata::Type.new(fields_by_name: {}, non_standard_enum_values_by_name: {}, scalar: nil) if abstract? fields_by_name = proto_fields.filter_map do |schema_field, field| base_type = _ = ObjectInterfaceAndUnionExtension.list_depth_and_base_type(field.type).last.resolved scalar = base_type..scalar if base_type.is_a?(ScalarTypeExtension) name_in_index = field.name_in_index unless field.name_in_index == schema_field.name next unless name_in_index || scalar [schema_field.name, RuntimeMetadata::Field.new(name_in_index: name_in_index, type: scalar ? base_type.name : nil)] end.to_h RuntimeMetadata::Type.new(fields_by_name: fields_by_name, non_standard_enum_values_by_name: {}, scalar: nil) end |
#proto_name ⇒ String
Returns this type's name in protobuf schemas.
78 79 80 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 78 def proto_name name end |
#proto_type_reference(package_name) ⇒ String
Returns the fully qualified name used to reference this message from protobuf fields.
85 86 87 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 85 def proto_type_reference(package_name) ".#{package_name}.#{proto_name}" end |
#protobuf_field_comment ⇒ nil
Messages carry their documentation on the message definition itself, so fields of this type get no format comment. Only scalar types document a format.
100 101 102 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 100 def protobuf_field_comment nil end |
#protobuf_import ⇒ nil
Messages render their own protobuf definition, so they never require an import.
92 93 94 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 92 def protobuf_import nil end |
#referenced_proto_types ⇒ Array
Returns the schema types referenced by this definition.
30 31 32 33 34 35 36 37 38 39 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 30 def referenced_proto_types if abstract? abstract_type = _ = self abstract_type.recursively_resolve_subtypes else proto_fields.map do |_, field| _ = field.type.fully_unwrapped.resolved end end end |
#to_proto(schema, package_name) ⇒ String
Renders this type's protobuf message definition.
23 24 25 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/object_interface_and_union_extension.rb', line 23 def to_proto(schema, package_name) (schema, proto_name, package_name) end |