Class: ElasticGraph::Indexer::RecordPreparer::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/indexer/record_preparer.rb

Overview

Provides the ability to get a ‘RecordPreparer` for a specific JSON schema version.

Instance Method Summary collapse

Constructor Details

#initialize(schema_artifacts) ⇒ Factory

Returns a new instance of Factory.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/elastic_graph/indexer/record_preparer.rb', line 16

def initialize(schema_artifacts)
  @schema_artifacts = schema_artifacts

  scalar_types_by_name = schema_artifacts..scalar_types_by_name
  indexing_preparer_by_scalar_type_name = ::Hash.new do |hash, type_name|
    hash[type_name] = scalar_types_by_name[type_name]&.load_indexing_preparer&.extension_class
  end

  @preparers_by_json_schema_version = ::Hash.new do |hash, version|
    hash[version] = RecordPreparer.new(
      indexing_preparer_by_scalar_type_name,
      build_type_metas_from(@schema_artifacts.json_schemas_for(version))
    )
  end
end

Instance Method Details

#for_json_schema_version(json_schema_version) ⇒ Object

Gets the ‘RecordPreparer` for the given JSON schema version.



33
34
35
# File 'lib/elastic_graph/indexer/record_preparer.rb', line 33

def for_json_schema_version(json_schema_version)
  @preparers_by_json_schema_version[json_schema_version]
end

#for_latest_json_schema_versionObject

Gets the ‘RecordPreparer` for the latest JSON schema version. Intended primarily for use in tests for convenience.



39
40
41
# File 'lib/elastic_graph/indexer/record_preparer.rb', line 39

def for_latest_json_schema_version
  for_json_schema_version(@schema_artifacts.latest_json_schema_version)
end