Class: Evilution::Mutator::Operator::MixinRemoval

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/mixin_removal.rb

Defined Under Namespace

Classes: ScopeFinder

Constant Summary collapse

MIXIN_METHODS =
%i[include extend prepend].freeze

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

clear_parse_cache!, #initialize, operator_name, parsed_tree_for

Constructor Details

This class inherits a constructor from Evilution::Mutator::Base

Instance Method Details

#call(subject, filter: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/evilution/mutator/operator/mixin_removal.rb', line 10

def call(subject, filter: nil)
  @subject = subject
  @file_source = File.read(subject.file_path)
  @mutations = []
  @filter = filter

  tree = self.class.parsed_tree_for(subject.file_path, @file_source)
  enclosing = find_enclosing_scope(tree, subject.line_number)
  return @mutations unless enclosing

  first_method_line = find_first_method_line(enclosing)
  return @mutations unless first_method_line == subject.line_number

  find_mixin_calls(enclosing).each do |call_node|
    add_mutation(
      offset: call_node.location.start_offset,
      length: call_node.location.length,
      replacement: "",
      node: call_node
    )
  end

  @mutations
end