Class: RSpecTracer::Tracker::NewFileDetector Private
- Inherits:
-
Object
- Object
- RSpecTracer::Tracker::NewFileDetector
- Defined in:
- lib/rspec_tracer/tracker/new_file_detector.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Observer #5 (composition of DeclaredGlobs + cache diff). Fixes KNOWN_ISSUES Section B5: 1.x’s fetch_changed_files loop only iterated the previous run’s cache, so newly-added source files were never discovered and never triggered re-runs.
The fix: at boot, walk the union of user-declared globs and a pure-Ruby default set (lib/*/.rb). Every match on disk that is not in the loaded cache’s known_paths emits an Input, which the filter engine treats as “added” and re-runs any example whose dependency graph could plausibly include it.
Kind is :declared for every emission. The pure-Ruby default is logically a pre-declared glob on the user’s behalf - the attribution semantics are identical to an explicit ‘track_files ’lib/*/.rb’‘.
The Rails preset (app/*/.rb) flows through Configuration#track_rails_defaults; the default list here stays framework-agnostic.
Constant Summary collapse
- DEFAULT_GLOBS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Internal constant.
%w[lib/**/*.rb].freeze
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
private
Internal attribute.
Instance Method Summary collapse
-
#initialize(root:, declared_globs: [], default_globs: DEFAULT_GLOBS) ⇒ NewFileDetector
constructor
private
Input contract: declared_globs and default_globs are Arrays of String glob patterns.
-
#new_files(known_paths:) ⇒ Object
private
Set<Input> for every on-disk match not present in the supplied known_paths Set.
Constructor Details
#initialize(root:, declared_globs: [], default_globs: DEFAULT_GLOBS) ⇒ NewFileDetector
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Input contract: declared_globs and default_globs are Arrays of String glob patterns. Configuration#declared_globs already normalizes user input (flatten / compact / to_s / uniq / freeze), and DeclaredGlobs#initialize re-applies the same coercion downstream (‘Array(globs).flatten.compact.map(&:to_s).uniq.freeze`), so this constructor stays narrow on purpose - any defensive coercion here would be triple-applied dead code.
46 47 48 49 |
# File 'lib/rspec_tracer/tracker/new_file_detector.rb', line 46 def initialize(root:, declared_globs: [], default_globs: DEFAULT_GLOBS) @root = File.(root) @walker = DeclaredGlobs.new(root: @root, globs: declared_globs + default_globs) end |
Instance Attribute Details
#root ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal attribute.
37 38 39 |
# File 'lib/rspec_tracer/tracker/new_file_detector.rb', line 37 def root @root end |
Instance Method Details
#new_files(known_paths:) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set<Input> for every on-disk match not present in the supplied known_paths Set. Called once per suite boot; the walker’s underlying digest work is memoized on the DeclaredGlobs instance so repeated calls within a single suite don’t re-hash. Engine#compute_change_set passes a Set directly; Set#include? is O(1) so no upstream ‘to_set` is needed.
57 58 59 |
# File 'lib/rspec_tracer/tracker/new_file_detector.rb', line 57 def new_files(known_paths:) @walker.walk.reject { |input| known_paths.include?(input.path) }.to_set end |