Class: ActiveCypher::Fixtures::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cypher/fixtures/evaluator.rb

Overview

Evaluator orchestrates node and relationship creation for a fixture profile.

Instance Method Summary collapse

Constructor Details

#initialize(registry: Registry, node_builder: NodeBuilder.new, rel_builder: RelBuilder.new) ⇒ Evaluator

Returns a new instance of Evaluator.



7
8
9
10
11
# File 'lib/active_cypher/fixtures/evaluator.rb', line 7

def initialize(registry: Registry, node_builder: NodeBuilder.new, rel_builder: RelBuilder.new)
  @registry = registry
  @node_builder = node_builder
  @rel_builder = rel_builder
end

Instance Method Details

#evaluate(instructions) ⇒ Object

Evaluate a sequence of DSL instructions (AST or direct calls). Each instruction is a hash: { type: :node/:relationship, args: […] }



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/active_cypher/fixtures/evaluator.rb', line 15

def evaluate(instructions)
  instructions.each do |inst|
    case inst[:type]
    when :node
      ref = inst[:ref]
      model_class = inst[:model_class]
      props = inst[:props]
      @node_builder.build(ref, model_class, props)
    when :relationship
      ref = inst[:ref]
      from_ref = inst[:from_ref]
      type = inst[:rel_type]
      to_ref = inst[:to_ref]
      props = inst[:props]
      @rel_builder.build(ref, from_ref, type, to_ref, props)
    else
      raise ArgumentError, "Unknown instruction type: #{inst[:type]}"
    end
  end
end