Class: ElasticGraph::ProtoIngestion::SchemaDefinition::Schema

Inherits:
Object
  • Object
show all
Defined in:
elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema.rb

Overview

Builds a proto3 schema string from an ElasticGraph schema definition.

Instance Method Summary collapse

Constructor Details

#initialize(state:, all_types:, package_name:) ⇒ Schema

Returns a new instance of Schema.

Parameters:

  • state (ElasticGraph::SchemaDefinition::State)
  • all_types (Array<ElasticGraph::SchemaDefinition::SchemaElements::graphQLType>)
  • package_name (String)


22
23
24
25
26
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema.rb', line 22

def initialize(state:, all_types:, package_name:)
  @state = state
  @all_types = all_types
  @package_name = package_name
end

Instance Method Details

#to_protoString

Renders the schema as a valid proto3 file.

Returns:

  • (String)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'elasticgraph-proto_ingestion/lib/elastic_graph/proto_ingestion/schema_definition/schema.rb', line 31

def to_proto
  types = proto_types
  return "" if types.empty?

  validate_unique_enum_value_prefixes(types)

  sections = [
    %(syntax = "proto3";),
    "package #{@package_name};",
    render_definitions(types)
  ]

  sections.join("\n\n") + "\n"
end