Class: Evilution::ExampleFilter

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

Instance Method Summary collapse

Constructor Details

#initialize(cache:, fallback: :full_file, source_cache: nil) ⇒ ExampleFilter

Returns a new instance of ExampleFilter.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'lib/evilution/example_filter.rb', line 11

def initialize(cache:, fallback: :full_file, source_cache: nil)
  raise ArgumentError, "invalid fallback: #{fallback.inspect}" unless VALID_FALLBACKS.include?(fallback)

  @cache = cache
  @fallback = fallback
  @source_cache = source_cache
end

Instance Method Details

#call(mutation, spec_paths) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/evilution/example_filter.rb', line 19

def call(mutation, spec_paths)
  return fallback_result(spec_paths) if spec_paths.nil? || spec_paths.empty?

  token = extract_token(mutation)
  return fallback_result(spec_paths) unless token

  locations = scan_specs(token, spec_paths)
  return fallback_result(spec_paths) if locations.empty?

  locations.sort
end