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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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

  @constant_pinner.call(mutation.original_source)
  @concern_state_cleaner.call(mutation.file_path)
  @redefinition_recovery.call(mutation.original_source) do
    @source_evaluator.call(mutation.mutated_source, mutation.file_path)
  end
  nil
rescue SyntaxError => e
  {
    passed: false,
    error: "syntax error in mutated source: #{e.message}",
    error_class: e.class.name,
    error_backtrace: Array(e.backtrace).first(5)
  }
rescue ScriptError, StandardError => e
  {
    passed: false,
    error: "#{e.class}: #{e.message}",
    error_class: e.class.name,
    error_backtrace: Array(e.backtrace).first(5)
  }
end