Class: ElasticGraph::Indexer::Operation::Factory
- Inherits:
-
Object
- Object
- ElasticGraph::Indexer::Operation::Factory
- Defined in:
- lib/elastic_graph/indexer/operation/factory.rb
Defined Under Namespace
Classes: BuildResult
Instance Method Summary collapse
Instance Method Details
#build(event) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/elastic_graph/indexer/operation/factory.rb', line 28 def build(event) event = prepare_event(event) selected_json_schema_version = select_json_schema_version(event) { |failure| return failure } # Because the `select_json_schema_version` picks the closest-matching json schema version, the incoming # event might not match the expected json_schema_version value in the json schema (which is a `const` field). # This is by design, since we're picking a schema based on best-effort, so to avoid that by-design validation error, # performing the envelope validation on a "patched" version of the event. event_with_patched_envelope = event.merge({JSON_SCHEMA_VERSION_KEY => selected_json_schema_version}) if ( = validator(EVENT_ENVELOPE_JSON_SCHEMA_NAME, selected_json_schema_version).(event_with_patched_envelope)) return build_failed_result(event, "event payload", ) end failed_result = validate_record_returning_failure(event, selected_json_schema_version) failed_result || BuildResult.success(build_all_operations_for( event, record_preparer_factory.for_json_schema_version(selected_json_schema_version) )) end |