Class: FastCov::AbstractTracker
- Inherits:
-
Object
- Object
- FastCov::AbstractTracker
- Defined in:
- lib/fast_cov/trackers/abstract_tracker.rb
Overview
Base class for trackers that record file paths during coverage.
Provides common functionality:
-
Path filtering (root, ignored_paths)
-
Thread-aware recording (CoverageMap#threads)
-
File collection and lifecycle management
Descendants override hooks: on_start, on_stop, on_record Or implement start, stop, record directly without inheriting.
Threading behavior:
-
threads: true -> record from ALL threads (global tracking)
-
threads: false -> only record from the thread that called start
Direct Known Subclasses
ConstGetTracker, FactoryBotTracker, FileTracker, FixtureKitTracker
Class Attribute Summary collapse
-
.active ⇒ Object
Returns the value of attribute active.
Instance Attribute Summary collapse
-
#coverage_map ⇒ Object
readonly
Returns the value of attribute coverage_map.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(coverage_map, **_options) ⇒ AbstractTracker
constructor
A new instance of AbstractTracker.
-
#install ⇒ Object
Hooks for descendants - override as needed.
- #on_record(path) ⇒ Object
- #on_start ⇒ Object
- #on_stop ⇒ Object
- #record(abs_path, to: nil) ⇒ Object
- #root ⇒ Object
-
#start ⇒ Object
Public API - called by FastCov framework.
- #stop ⇒ Object
Constructor Details
#initialize(coverage_map, **_options) ⇒ AbstractTracker
Returns a new instance of AbstractTracker.
20 21 22 23 24 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 20 def initialize(coverage_map, **) @coverage_map = coverage_map @files = nil @started_thread = nil end |
Class Attribute Details
.active ⇒ Object
Returns the value of attribute active.
77 78 79 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 77 def active @active end |
Instance Attribute Details
#coverage_map ⇒ Object (readonly)
Returns the value of attribute coverage_map.
18 19 20 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 18 def coverage_map @coverage_map end |
Class Method Details
.record(path, to: nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 79 def record(path, to: nil) return unless active return unless path to ||= Utils.resolve_caller(caller_locations(1, 20), active.root) active.record(path, to: to) end |
.reset ⇒ Object
87 88 89 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 87 def reset @active = nil end |
Instance Method Details
#install ⇒ Object
Hooks for descendants - override as needed
60 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 60 def install; end |
#on_record(path) ⇒ Object
64 65 66 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 64 def on_record(path) true end |
#on_start ⇒ Object
61 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 61 def on_start; end |
#on_stop ⇒ Object
62 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 62 def on_stop; end |
#record(abs_path, to: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 48 def record(abs_path, to: nil) return if !@coverage_map.threads && Thread.current != @started_thread path = normalize_path(abs_path) return unless @coverage_map.include_path?(path) @coverage_map.connect(from: to, to: path) if to @files.add(path) if on_record(path) end |
#root ⇒ Object
26 27 28 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 26 def root coverage_map.root end |
#start ⇒ Object
Public API - called by FastCov framework
32 33 34 35 36 37 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 32 def start @files = Set.new @started_thread = Thread.current unless @coverage_map.threads self.class.active = self on_start end |
#stop ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/fast_cov/trackers/abstract_tracker.rb', line 39 def stop self.class.active = nil @started_thread = nil on_stop result = @files @files = nil result end |