Class: ElasticGraph::JSONIngestion::RecordPreparerFactory

Inherits:
Object
  • Object
show all
Defined in:
elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/record_preparer_factory.rb

Overview

Provides the ability to get an ElasticGraph::Indexer::RecordPreparer for a specific JSON schema version, deriving each version's per-type field metadata from that version's JSON schemas.

Instance Method Summary collapse

Constructor Details

#initialize(schema_artifacts) ⇒ RecordPreparerFactory

Returns a new instance of RecordPreparerFactory.

Parameters:



19
20
21
22
23
24
25
26
27
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/record_preparer_factory.rb', line 19

def initialize(schema_artifacts)
  @schema_artifacts = schema_artifacts

  @indexing_preparer_by_scalar_type_name = schema_artifacts..scalar_types_by_name.transform_values do |scalar_type|
    scalar_type.load_indexing_preparer.extension_class
  end # : ::Hash[::String, SchemaArtifacts::RuntimeMetadata::extensionClass?]

  @preparers_by_json_schema_version = Support::ThreadSafeCache.new # : Support::ThreadSafeCache[::Integer, ElasticGraph::Indexer::RecordPreparer]
end

Instance Method Details

#for_json_schema_version(json_schema_version) ⇒ ElasticGraph::Indexer::RecordPreparer

Gets the ElasticGraph::Indexer::RecordPreparer for the given JSON schema version.

Parameters:

  • json_schema_version (Integer) —

    the JSON schema version

Returns:

  • (ElasticGraph::Indexer::RecordPreparer) —

    the record preparer for the given version



33
34
35
36
37
38
39
40
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/record_preparer_factory.rb', line 33

def for_json_schema_version(json_schema_version)
  @preparers_by_json_schema_version.fetch_or_store(json_schema_version) do
    ElasticGraph::Indexer::RecordPreparer.new(
      @indexing_preparer_by_scalar_type_name,
      build_type_metas_from(@schema_artifacts.json_schemas_for(json_schema_version))
    )
  end
end

#for_latest_json_schema_version ⇒ ElasticGraph::Indexer::RecordPreparer

Gets the ElasticGraph::Indexer::RecordPreparer for the latest JSON schema version. Intended primarily for use in tests for convenience.

Returns:

  • (ElasticGraph::Indexer::RecordPreparer) —

    the record preparer for the latest version



46
47
48
# File 'elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/record_preparer_factory.rb', line 46

def for_latest_json_schema_version
  for_json_schema_version(@schema_artifacts.latest_json_schema_version)
end