Class: Crystalball::MapGenerator::ObjectSourcesDetector

Inherits:
Object
  • Object
show all
Includes:
Helpers::PathFilter
Defined in:
lib/crystalball/map_generator/object_sources_detector.rb,
lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb,
lib/crystalball/map_generator/object_sources_detector/hierarchy_fetcher.rb

Overview

Class for files paths affected object definition

Defined Under Namespace

Classes: DefinitionTracer, HierarchyFetcher

Instance Attribute Summary collapse

Attributes included from Helpers::PathFilter

#root_path

Instance Method Summary collapse

Methods included from Helpers::PathFilter

#filter

Constructor Details

#initialize(root_path:, definition_tracer: DefinitionTracer.new(root_path), hierarchy_fetcher: HierarchyFetcher.new) ⇒ ObjectSourcesDetector

Returns a new instance of ObjectSourcesDetector.



15
16
17
18
19
20
21
22
23
24
# File 'lib/crystalball/map_generator/object_sources_detector.rb', line 15

def initialize(
  root_path:,
  definition_tracer: DefinitionTracer.new(root_path),
  hierarchy_fetcher: HierarchyFetcher.new
)
  super(root_path)

  @definition_tracer = definition_tracer
  @hierarchy_fetcher = hierarchy_fetcher
end

Instance Attribute Details

#definition_tracerObject (readonly)

Returns the value of attribute definition_tracer.



13
14
15
# File 'lib/crystalball/map_generator/object_sources_detector.rb', line 13

def definition_tracer
  @definition_tracer
end

#hierarchy_fetcherObject (readonly)

Returns the value of attribute hierarchy_fetcher.



13
14
15
# File 'lib/crystalball/map_generator/object_sources_detector.rb', line 13

def hierarchy_fetcher
  @hierarchy_fetcher
end

Instance Method Details

#after_registerObject



26
27
28
# File 'lib/crystalball/map_generator/object_sources_detector.rb', line 26

def after_register
  definition_tracer.start
end

#before_finalizeObject



30
31
32
# File 'lib/crystalball/map_generator/object_sources_detector.rb', line 30

def before_finalize
  definition_tracer.stop
end

#detect(objects) ⇒ Array<String>

Detects files affected during example execution. Transforms absolute paths to relative. Exclude paths outside of repository

@param list of files affected before example execution

Returns:

  • (Array<String>)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/crystalball/map_generator/object_sources_detector.rb', line 39

def detect(objects)
  modules = objects.map do |object|
    object.is_a?(Module) ? object : object.class
  end.uniq

  paths = modules.flat_map do |mod|
    hierarchy_fetcher.ancestors_for(mod).flat_map do |ancestor|
      definition_tracer.constants_definition_paths[ancestor]
    end
  end.compact.uniq

  filter paths
end