Class: Henitai::Mutant::Activator

Inherits:
Object
  • Object
show all
Includes:
ConstantRedefinitionFilter
Defined in:
lib/henitai/mutant/activator.rb

Overview

Activates a mutant inside the forked child process.

Defined Under Namespace

Modules: ConstantRedefinitionFilter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConstantRedefinitionFilter

#warn

Class Method Details

.activate!(mutant) ⇒ Object



26
27
28
# File 'lib/henitai/mutant/activator.rb', line 26

def self.activate!(mutant)
  new.activate!(mutant)
end

.activation_source_for(mutant) ⇒ Object

Returns the define_method source string for mutant without actually evaluating it. Used to pre-compute activation recipes. Returns nil if the source cannot be computed (e.g. unsupported AST node).



33
34
35
36
37
# File 'lib/henitai/mutant/activator.rb', line 33

def self.activation_source_for(mutant)
  new.send(:method_source, mutant)
rescue StandardError
  nil
end

Instance Method Details

#activate!(mutant) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/henitai/mutant/activator.rb', line 39

def activate!(mutant)
  subject = mutant.subject
  raise ArgumentError, "Cannot activate wildcard subjects" if subject.method_name.nil?

  source = mutant.precomputed_activation_source || method_source(mutant)
  target = target_for(subject)
  Henitai::WarningSilencer.silence do
    target.class_eval(source, __FILE__, __LINE__ + 1)
    nil
  end
rescue Unparser::UnsupportedNodeError, SyntaxError
  :compile_error
end