Class: Synthra::REPL::DebugEngine
- Inherits:
-
Object
- Object
- Synthra::REPL::DebugEngine
- Defined in:
- lib/synthra/repl/formatter.rb
Overview
Debug-enabled engine wrapper
Instance Method Summary collapse
-
#generate ⇒ Hash
Generate with debugging.
-
#initialize(schema, registry: nil, mode: :random, seed: nil) ⇒ DebugEngine
constructor
A new instance of DebugEngine.
-
#on_field_generated {|schema_name, field_name, value, duration_ms| ... } ⇒ Object
Add debug callback.
Constructor Details
#initialize(schema, registry: nil, mode: :random, seed: nil) ⇒ DebugEngine
Returns a new instance of DebugEngine.
151 152 153 154 155 156 157 |
# File 'lib/synthra/repl/formatter.rb', line 151 def initialize(schema, registry: nil, mode: :random, seed: nil) @schema = schema @registry = registry @mode = mode @seed = seed @debug_callbacks = [] end |
Instance Method Details
#generate ⇒ Hash
Generate with debugging
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/synthra/repl/formatter.rb', line 172 def generate # Create a custom configuration that triggers callbacks original_callback = Synthra.configuration.on_field_generated # The engine calls on_field_generated with 4 args: schema_name, field_name, value, duration_ms Synthra.configuration.on_field_generated = lambda do |schema_name, field_name, value, duration_ms| original_callback&.call(schema_name, field_name, value, duration_ms) @debug_callbacks.each { |cb| cb.call(schema_name, field_name, value, duration_ms) } end begin engine = Generator::Engine.new(@schema, registry: @registry) engine.generate(seed: @seed, mode: @mode) ensure Synthra.configuration.on_field_generated = original_callback end end |
#on_field_generated {|schema_name, field_name, value, duration_ms| ... } ⇒ Object
Note:
The callback receives 4 arguments matching the engine's on_field_generated signature
Add debug callback
164 165 166 |
# File 'lib/synthra/repl/formatter.rb', line 164 def on_field_generated(&block) @debug_callbacks << block end |