Class: Evilution::Integration::Loading::MutationApplier

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/integration/loading/mutation_applier.rb

Overview

Composes the load-time pipeline that applies a mutation’s new source to the running VM: syntax-validate -> pin top-level constants (beats Zeitwerk) -> clear AS::Concern state -> eval inside a redefinition-recovery wrapper. Returns nil on success or a failure-shaped hash on any error.

Instance Method Summary collapse

Constructor Details

#initialize(syntax_validator: Evilution::Integration::Loading::SyntaxValidator.new, constant_pinner: Evilution::Integration::Loading::ConstantPinner.new, concern_state_cleaner: Evilution::Integration::Loading::ConcernStateCleaner.new, source_evaluator: Evilution::Integration::Loading::SourceEvaluator.new, redefinition_recovery: Evilution::Integration::Loading::RedefinitionRecovery.new) ⇒ MutationApplier

Returns a new instance of MutationApplier.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/evilution/integration/loading/mutation_applier.rb', line 15

def initialize(syntax_validator: Evilution::Integration::Loading::SyntaxValidator.new,
               constant_pinner: Evilution::Integration::Loading::ConstantPinner.new,
               concern_state_cleaner: Evilution::Integration::Loading::ConcernStateCleaner.new,
               source_evaluator: Evilution::Integration::Loading::SourceEvaluator.new,
               redefinition_recovery: Evilution::Integration::Loading::RedefinitionRecovery.new)
  @syntax_validator = syntax_validator
  @constant_pinner = constant_pinner
  @concern_state_cleaner = concern_state_cleaner
  @source_evaluator = source_evaluator
  @redefinition_recovery = redefinition_recovery
end

Instance Method Details

#call(mutation) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/evilution/integration/loading/mutation_applier.rb', line 27

def call(mutation)
  syntax_error = @syntax_validator.call(mutation.mutated_source)
  return syntax_error if syntax_error

  apply(mutation)
  nil
rescue SyntaxError => e
  failure_result(e, "syntax error in mutated source: #{e.message}")
rescue ScriptError, StandardError => e
  failure_result(e, "#{e.class}: #{e.message}")
end