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

Instance Method Summary collapse

Instance Attribute Details

#protobuf_typeObject (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.

Yields:

  • additional scalar type configuration

Raises:

  • (Errors::SchemaError)

    when a protobuf type is missing



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_nameString

Returns this scalar's name in protobuf schemas.

Returns:

  • (String)


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.

Returns:

  • (String)


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.

Parameters:

  • type (String)

    protobuf scalar type name



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_typesArray

Returns the schema types referenced by this definition.

Returns:

  • (Array)


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.

Returns:

  • (nil)


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