Class: ElasticGraph::SchemaDefinition::Indexing::UpdateTargetResolver
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaDefinition::Indexing::UpdateTargetResolver
- Defined in:
- lib/elastic_graph/schema_definition/indexing/update_target_resolver.rb
Overview
Responsible for resolving a relationship and a set of ‘sourced_from` fields into an `UpdateTarget` that contains the instructions for how the primary type should be updated from the related type’s source events.
Defined Under Namespace
Modules: RolloverTimestampSourceAdapter, RoutingSourceAdapter
Instance Method Summary collapse
-
#initialize(object_type:, resolved_relationship:, sourced_fields:, field_path_resolver:) ⇒ UpdateTargetResolver
constructor
A new instance of UpdateTargetResolver.
-
#resolve ⇒ Object
Resolves the ‘object_type`, `resolved_relationship`, and `sourced_fields` into an `UpdateTarget`, validating that everything is defined correctly.
Constructor Details
#initialize(object_type:, resolved_relationship:, sourced_fields:, field_path_resolver:) ⇒ UpdateTargetResolver
Returns a new instance of UpdateTargetResolver.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/elastic_graph/schema_definition/indexing/update_target_resolver.rb', line 21 def initialize( object_type:, resolved_relationship:, sourced_fields:, field_path_resolver: ) @object_type = object_type @resolved_relationship = resolved_relationship @sourced_fields = sourced_fields @field_path_resolver = field_path_resolver end |
Instance Method Details
#resolve ⇒ Object
Resolves the ‘object_type`, `resolved_relationship`, and `sourced_fields` into an `UpdateTarget`, validating that everything is defined correctly.
Returns a tuple of the ‘update_target` (if valid), and a list of errors.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elastic_graph/schema_definition/indexing/update_target_resolver.rb', line 37 def resolve relationship_errors = validate_relationship data_params, data_params_errors = resolve_data_params routing_value_source, routing_error = resolve_field_source(RoutingSourceAdapter) , = resolve_field_source(RolloverTimestampSourceAdapter) equivalent_field_errors = resolved_relationship.relationship.validate_equivalent_fields(field_path_resolver) all_errors = relationship_errors + data_params_errors + equivalent_field_errors + [routing_error, ].compact if all_errors.empty? update_target = UpdateTargetFactory.new_normal_indexing_update_target( type: object_type.name, relationship: resolved_relationship.relationship_name, id_source: resolved_relationship..foreign_key, data_params: data_params, routing_value_source: routing_value_source, rollover_timestamp_value_source: ) end [update_target, all_errors] end |