Class: Bootsnap::LoadPathCache::Path
- Inherits:
-
Object
- Object
- Bootsnap::LoadPathCache::Path
- Defined in:
- lib/bootsnap/load_path_cache/path.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#entries_and_dirs(store) ⇒ Object
Return a list of all the requirable files and all of the subdirectories of this
Path
. - #expanded_path ⇒ Object
-
#initialize(path, real: false) ⇒ Path
constructor
A new instance of Path.
-
#non_directory? ⇒ Boolean
True if the path exists, but represents a non-directory object.
- #relative? ⇒ Boolean
-
#stable? ⇒ Boolean
A path is considered ‘stable’ if it is part of a Gem.path or the ruby distribution.
- #to_realpath ⇒ Object
-
#volatile? ⇒ Boolean
A path is considered volatile if it doesn’t live under a Gem.path or the ruby distribution root.
Constructor Details
#initialize(path, real: false) ⇒ Path
Returns a new instance of Path.
24 25 26 27 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 24 def initialize(path, real: false) @path = path.to_s.freeze @real = real end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
22 23 24 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 22 def path @path end |
Instance Method Details
#entries_and_dirs(store) ⇒ Object
Return a list of all the requirable files and all of the subdirectories of this Path
.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 59 def entries_and_dirs(store) if stable? # the cached_mtime field is unused for 'stable' paths, but is # set to zero anyway, just in case we change the stability heuristics. _, entries, dirs = store.get() return [entries, dirs] if entries # cache hit entries, dirs = scan! store.set(, [0, entries, dirs]) return [entries, dirs] end cached_mtime, entries, dirs = store.get() current_mtime = latest_mtime(, dirs || []) return [[], []] if current_mtime == -1 # path does not exist return [entries, dirs] if cached_mtime == current_mtime entries, dirs = scan! store.set(, [current_mtime, entries, dirs]) [entries, dirs] end |
#expanded_path ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 82 def if @real path else @expanded_path ||= File.(path).freeze end end |
#non_directory? ⇒ Boolean
True if the path exists, but represents a non-directory object
47 48 49 50 51 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 47 def non_directory? !File.stat(path).directory? rescue Errno::ENOENT, Errno::ENOTDIR, Errno::EINVAL false end |
#relative? ⇒ Boolean
53 54 55 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 53 def relative? !path.start_with?(SLASH) end |
#stable? ⇒ Boolean
A path is considered ‘stable’ if it is part of a Gem.path or the ruby distribution. When adding or removing files in these paths, the cache must be cleared before the change will be noticed.
11 12 13 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 11 def stable? stability == STABLE end |
#to_realpath ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 29 def to_realpath return self if @real realpath = begin File.realpath(path) rescue Errno::ENOENT return self end if realpath == path @real = true self else Path.new(realpath, real: true) end end |
#volatile? ⇒ Boolean
A path is considered volatile if it doesn’t live under a Gem.path or the ruby distribution root. These paths are scanned for new additions more frequently.
18 19 20 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 18 def volatile? stability == VOLATILE end |