Module: Bootsnap::LoadPathCache::PathScanner
- Defined in:
- lib/bootsnap/load_path_cache/path_scanner.rb
Constant Summary collapse
- REQUIRABLE_EXTENSIONS =
[DOT_RB] + DL_EXTENSIONS
- BUNDLE_PATH =
if Bootsnap.bundler? (Bundler.bundle_path.cleanpath.to_s << LoadPathCache::SLASH).freeze else "" end
Class Attribute Summary collapse
-
.ignored_directories ⇒ Object
Returns the value of attribute ignored_directories.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.ignored_directories ⇒ Object
Returns the value of attribute ignored_directories.
19 20 21 |
# File 'lib/bootsnap/load_path_cache/path_scanner.rb', line 19 def ignored_directories @ignored_directories end |
Class Method Details
.ruby_call(root_path) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bootsnap/load_path_cache/path_scanner.rb', line 21 def ruby_call(root_path) root_path, contains_bundle_path, ignored_abs_paths, ignored_dir_names = prepare_scan(root_path) return [] unless File.directory?(root_path) requirables = [] walk(root_path, nil, ignored_abs_paths, ignored_dir_names) do |relative_path, absolute_path, is_directory| if is_directory !contains_bundle_path || !absolute_path.start_with?(BUNDLE_PATH) elsif relative_path.end_with?(*REQUIRABLE_EXTENSIONS) requirables << relative_path.freeze end end requirables end |
Instance Method Details
#native_call(root_path) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bootsnap/load_path_cache/path_scanner.rb', line 41 def native_call(root_path) # NOTE: if https://bugs.ruby-lang.org/issues/21800 is accepted we should be able # to have similar performance with pure Ruby root_path, contains_bundle_path, ignored_abs_paths, ignored_dir_names = prepare_scan(root_path) all_requirables, queue = Native.scan_dir(root_path) all_requirables.each(&:freeze) queue.reject! do |dir| if ignored_dir_names&.include?(dir) true elsif ignored_abs_paths || contains_bundle_path absolute_dir = File.join(root_path, dir) ignored_abs_paths&.include?(absolute_dir) || (contains_bundle_path && absolute_dir.start_with?(BUNDLE_PATH)) end end while (relative_path = queue.pop) absolute_base = File.join(root_path, relative_path) requirables, dirs = Native.scan_dir(absolute_base) dirs.reject! do |dir| if ignored_dir_names&.include?(dir) true elsif ignored_abs_paths || contains_bundle_path absolute_dir = File.join(absolute_base, dir) ignored_abs_paths&.include?(absolute_dir) || (contains_bundle_path && absolute_dir.start_with?(BUNDLE_PATH)) end end dirs.map! { |f| File.join(relative_path, f).freeze } requirables.map! { |f| File.join(relative_path, f).freeze } all_requirables.concat(requirables) queue.concat(dirs) end all_requirables end |