Class: FactDb::Pipeline::ResolutionPipeline
- Inherits:
-
Object
- Object
- FactDb::Pipeline::ResolutionPipeline
- Defined in:
- lib/fact_db/pipeline/resolution_pipeline.rb
Overview
Pipeline for resolving entities and facts using SimpleFlow Supports parallel resolution of multiple items
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#entity_resolver ⇒ Object
readonly
Returns the value of attribute entity_resolver.
-
#fact_resolver ⇒ Object
readonly
Returns the value of attribute fact_resolver.
Instance Method Summary collapse
-
#detect_conflicts(entity_ids) ⇒ Array<Hash>
Find and resolve conflicts for multiple entities in parallel.
-
#initialize(config = FactDb.config) ⇒ ResolutionPipeline
constructor
A new instance of ResolutionPipeline.
-
#resolve_entities(names, kind: nil) ⇒ Array<Hash>
Resolve multiple entity names in parallel.
Constructor Details
#initialize(config = FactDb.config) ⇒ ResolutionPipeline
Returns a new instance of ResolutionPipeline.
17 18 19 20 21 |
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 17 def initialize(config = FactDb.config) @config = config @entity_resolver = Resolution::EntityResolver.new(config) @fact_resolver = Resolution::FactResolver.new(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 15 def config @config end |
#entity_resolver ⇒ Object (readonly)
Returns the value of attribute entity_resolver.
15 16 17 |
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 15 def entity_resolver @entity_resolver end |
#fact_resolver ⇒ Object (readonly)
Returns the value of attribute fact_resolver.
15 16 17 |
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 15 def fact_resolver @fact_resolver end |
Instance Method Details
#detect_conflicts(entity_ids) ⇒ Array<Hash>
Find and resolve conflicts for multiple entities in parallel
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 49 def detect_conflicts(entity_ids) pipeline = build_conflict_detection_pipeline(entity_ids) initial_result = SimpleFlow::Result.new(entity_ids: entity_ids, conflicts: {}) final_result = pipeline.call(initial_result) entity_ids.map do |entity_id| conflicts = final_result.value[:conflicts][entity_id] { entity_id: entity_id, conflicts: conflicts || [], conflict_count: conflicts&.size || 0 } end end |
#resolve_entities(names, kind: nil) ⇒ Array<Hash>
Resolve multiple entity names in parallel
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 28 def resolve_entities(names, kind: nil) pipeline = build_entity_resolution_pipeline(names, kind) initial_result = SimpleFlow::Result.new(names: names, resolved: {}) final_result = pipeline.call(initial_result) names.map do |name| resolution = final_result.value[:resolved][name] { name: name, entity: resolution&.dig(:entity), status: resolution&.dig(:status) || :failed, error: resolution&.dig(:error) } end end |