Class: Henitai::Mutant::Activator
- Inherits:
-
Object
- Object
- Henitai::Mutant::Activator
- Includes:
- ConstantRedefinitionFilter
- Defined in:
- lib/henitai/mutant/activator.rb
Overview
Activates a mutant inside the forked child process. rubocop:disable Metrics/ClassLength
Defined Under Namespace
Modules: ConstantRedefinitionFilter
Constant Summary collapse
- SERIALIZER_METHODS =
{ arg: :argument_parameter_fragment, optarg: :optional_parameter_fragment, restarg: :rest_parameter_fragment, kwarg: :keyword_parameter_fragment, kwoptarg: :optional_keyword_parameter_fragment, kwrestarg: :keyword_rest_parameter_fragment, blockarg: :block_parameter_fragment, forward_arg: :forward_parameter_fragment }.freeze
Class Method Summary collapse
- .activate!(mutant) ⇒ Object
-
.activation_source_for(mutant) ⇒ Object
Returns the
define_methodsource string formutantwithout actually evaluating it.
Instance Method Summary collapse
Methods included from ConstantRedefinitionFilter
Class Method Details
.activate!(mutant) ⇒ Object
38 39 40 |
# File 'lib/henitai/mutant/activator.rb', line 38 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).
45 46 47 48 49 |
# File 'lib/henitai/mutant/activator.rb', line 45 def self.activation_source_for(mutant) new.send(:method_source, mutant) rescue StandardError nil end |
Instance Method Details
#activate!(mutant) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/henitai/mutant/activator.rb', line 51 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 |