Class: Evilution::Mutation

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/mutation.rb

Defined Under Namespace

Classes: Location, Slice, Sources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject:, operator_name:, sources:, location:, slice: nil, parse_status: :ok, eval_source: nil) ⇒ Mutation

Returns a new instance of Mutation.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/evilution/mutation.rb', line 13

def initialize(subject:, operator_name:, sources:, location:,
               slice: nil, parse_status: :ok, eval_source: nil)
  @subject = subject
  @operator_name = operator_name
  @sources = sources
  @location = location
  @slice = slice
  @parse_status = parse_status
  @eval_source = eval_source
  @diff = nil
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



11
12
13
# File 'lib/evilution/mutation.rb', line 11

def location
  @location
end

#operator_nameObject (readonly)

Returns the value of attribute operator_name.



11
12
13
# File 'lib/evilution/mutation.rb', line 11

def operator_name
  @operator_name
end

#parse_statusObject (readonly)

Returns the value of attribute parse_status.



11
12
13
# File 'lib/evilution/mutation.rb', line 11

def parse_status
  @parse_status
end

#subjectObject (readonly)

Returns the value of attribute subject.



11
12
13
# File 'lib/evilution/mutation.rb', line 11

def subject
  @subject
end

Instance Method Details

#columnObject



59
60
61
# File 'lib/evilution/mutation.rb', line 59

def column
  @location.column
end

#diffObject



67
68
69
# File 'lib/evilution/mutation.rb', line 67

def diff
  @diff ||= compute_diff
end

#eval_sourceObject

Source to feed to the load-time evaluator. Defaults to mutated_source when no pre-eval transform was applied at generation time. Mutator::Base populates this with the neutralized version (top-level idempotency- violating calls replaced with ‘nil`) so the worker eval doesn’t re-run them. The neutralization Prism parse happens once at generation time, not per worker iteration.



39
40
41
# File 'lib/evilution/mutation.rb', line 39

def eval_source
  @eval_source || mutated_source
end

#file_pathObject



51
52
53
# File 'lib/evilution/mutation.rb', line 51

def file_path
  @location.file_path
end

#lineObject



55
56
57
# File 'lib/evilution/mutation.rb', line 55

def line
  @location.line
end

#mutated_sliceObject



47
48
49
# File 'lib/evilution/mutation.rb', line 47

def mutated_slice
  @slice&.mutated
end

#mutated_sourceObject



29
30
31
# File 'lib/evilution/mutation.rb', line 29

def mutated_source
  @sources&.mutated
end

#original_sliceObject



43
44
45
# File 'lib/evilution/mutation.rb', line 43

def original_slice
  @slice&.original
end

#original_sourceObject



25
26
27
# File 'lib/evilution/mutation.rb', line 25

def original_source
  @sources&.original
end

#strip_sources!Object



77
78
79
80
# File 'lib/evilution/mutation.rb', line 77

def strip_sources!
  diff # ensure diff is cached before clearing sources
  @sources = nil
end

#to_sObject



82
83
84
# File 'lib/evilution/mutation.rb', line 82

def to_s
  "#{operator_name}: #{file_path}:#{line}"
end

#unified_diffObject



71
72
73
74
75
# File 'lib/evilution/mutation.rb', line 71

def unified_diff
  return @unified_diff if defined?(@unified_diff)

  @unified_diff = compute_unified_diff
end

#unparseable?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/evilution/mutation.rb', line 63

def unparseable?
  @parse_status == :unparseable
end