Module: ElasticGraph::ProtoIngestion::SchemaDefinition::SchemaElements::EnumTypeExtension

Defined in:
elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb

Overview

Extends EnumType with proto field type conversion.

Instance Method Summary collapse

Instance Method Details

#proto_enum_value_prefixString

Returns the package-level prefix applied to this enum's protobuf values.

Returns:

  • (String)


73
74
75
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb', line 73

def proto_enum_value_prefix
  @proto_enum_value_prefix ||= Support::Casing.to_upper_snake(name)
end

#proto_nameString

Returns this enum type's name in protobuf schemas.

Returns:

  • (String)


59
60
61
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb', line 59

def proto_name
  name
end

#proto_type_reference(package_name) ⇒ String

Returns the fully qualified name used to reference this enum from protobuf fields.

Returns:

  • (String)


66
67
68
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb', line 66

def proto_type_reference(package_name)
  ".#{package_name}.#{proto_name}"
end

#referenced_proto_typesArray

Returns the schema types referenced by this definition.

Returns:

  • (Array)


52
53
54
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb', line 52

def referenced_proto_types
  []
end

#to_proto(_package_name) ⇒ String

Renders this enum's protobuf definition.

Returns:

  • (String)


45
46
47
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb', line 45

def to_proto(_package_name)
  render_proto_enum
end

#value(value_name) ⇒ void

This method returns an undefined value.

Defines an enum value and immediately validates its protobuf name.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema_elements/enum_type_extension.rb', line 23

def value(value_name)
  super(value_name) do |new_value|
    new_proto_name = new_value.proto_name(proto_enum_value_prefix)

    if new_proto_name == proto_zero_value_name
      raise Errors::SchemaError, "Enum `#{name}` value `#{new_value.name}` maps to proto enum value name " \
        "`#{new_proto_name}`, which conflicts with the generated zero value `#{proto_zero_value_name}`."
    end

    if (duplicate = values_by_proto_name[new_proto_name])
      raise Errors::SchemaError, "Enum `#{name}` values `#{duplicate.name}` and `#{new_value.name}` " \
        "map to duplicate proto enum value name `#{new_proto_name}`."
    end

    yield new_value if block_given?
    values_by_proto_name[new_proto_name] = new_value
  end
end