Module: ElasticGraph::ProtoIngestion::SchemaDefinition::SchemaElements::ScalarTypeExtension
- Defined in:
- elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb
Overview
Extends ScalarType with proto field type conversion.
Constant Summary collapse
- BUILT_IN_SCALAR_PROTO_TYPES_BY_NAME =
Default protobuf types applied to ElasticGraph's built-in scalar types as they are constructed.
{ "Boolean" => "bool", "Cursor" => "string", "Date" => "string", "DateTime" => "string", "Float" => "double", "ID" => "string", "Int" => "int32", "JsonSafeLong" => "int64", "LocalTime" => "string", "LongString" => "int64", "String" => "string", "TimeZone" => "string", "Untyped" => "string" }.freeze
Instance Attribute Summary collapse
-
#protobuf_type ⇒ Object
readonly
Configured protobuf type (e.g. string, int64, bool).
Instance Method Summary collapse
-
#initialize_proto_extension { ... } ⇒ void
Applies any built-in protobuf type, yields for further configuration, and validates the result.
-
#proto_name ⇒ String
Returns this scalar's name in protobuf schemas.
-
#proto_type_reference(_package_name) ⇒ String
Returns this scalar's name when referenced by a protobuf field.
-
#protobuf(type:) ⇒ void
Configures the protobuf type for this scalar type.
-
#referenced_proto_types ⇒ Array
Returns the schema types referenced by this definition.
-
#to_proto(_package_name) ⇒ nil
Scalars map to protobuf field types and do not render standalone definitions.
Instance Attribute Details
#protobuf_type ⇒ Object (readonly)
Configured protobuf type (e.g. string, int64, bool).
36 37 38 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 36 def protobuf_type @protobuf_type end |
Instance Method Details
#initialize_proto_extension { ... } ⇒ void
This method returns an undefined value.
Applies any built-in protobuf type, yields for further configuration, and validates the result.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 51 def initialize_proto_extension original_name = type_ref.with_reverted_override.name if (proto_type = BUILT_IN_SCALAR_PROTO_TYPES_BY_NAME[original_name]) protobuf type: proto_type end yield return if graphql_only? proto_name nil end |
#proto_name ⇒ String
Returns this scalar's name in protobuf schemas.
81 82 83 84 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 81 def proto_name protobuf_type || raise(Errors::SchemaError, "Protobuf type not configured for scalar type `#{name}`. " \ 'To proceed, call `protobuf type: "TYPE"` on the scalar type definition.') end |
#proto_type_reference(_package_name) ⇒ String
Returns this scalar's name when referenced by a protobuf field.
89 90 91 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 89 def proto_type_reference(_package_name) proto_name end |
#protobuf(type:) ⇒ void
This method returns an undefined value.
Configures the protobuf type for this scalar type.
42 43 44 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 42 def protobuf(type:) @protobuf_type = type end |
#referenced_proto_types ⇒ Array
Returns the schema types referenced by this definition.
74 75 76 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 74 def referenced_proto_types [] end |
#to_proto(_package_name) ⇒ nil
Scalars map to protobuf field types and do not render standalone definitions.
67 68 69 |
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/scalar_type_extension.rb', line 67 def to_proto(_package_name) nil end |