Class: Crystalball::MapGenerator::ObjectSourcesDetector::DefinitionTracer
- Inherits:
-
Object
- Object
- Crystalball::MapGenerator::ObjectSourcesDetector::DefinitionTracer
- Defined in:
- lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb
Overview
Class to save paths to classes and modules definitions during code loading. Should be started as soon as possible. Use #constants_definition_paths to fetch traced info
Instance Attribute Summary collapse
-
#constants_definition_paths ⇒ Object
readonly
Returns the value of attribute constants_definition_paths.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#trace_point ⇒ Object
readonly
Returns the value of attribute trace_point.
Instance Method Summary collapse
-
#initialize(root_path) ⇒ DefinitionTracer
constructor
A new instance of DefinitionTracer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(root_path) ⇒ DefinitionTracer
Returns a new instance of DefinitionTracer.
11 12 13 14 |
# File 'lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb', line 11 def initialize(root_path) @root_path = root_path @constants_definition_paths = {} end |
Instance Attribute Details
#constants_definition_paths ⇒ Object
Returns the value of attribute constants_definition_paths.
9 10 11 |
# File 'lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb', line 9 def constants_definition_paths @constants_definition_paths end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
9 10 11 |
# File 'lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb', line 9 def root_path @root_path end |
#trace_point ⇒ Object
Returns the value of attribute trace_point.
9 10 11 |
# File 'lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb', line 9 def trace_point @trace_point end |
Instance Method Details
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb', line 16 def start self.trace_point ||= TracePoint.new(:class) do |tp| mod = tp.self path = tp.path next unless path&.start_with?(root_path) constants_definition_paths[mod] ||= [] constants_definition_paths[mod] << path end.tap(&:enable) end |
#stop ⇒ Object
28 29 30 31 |
# File 'lib/crystalball/map_generator/object_sources_detector/definition_tracer.rb', line 28 def stop trace_point&.disable self.trace_point = nil end |