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(store) ⇒ Object
Return a list of all the requirable files 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(store) ⇒ Object
Return a list of all the requirable files of this Path.
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.rb', line 58 def entries(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, = store.get() return entries if entries # cache hit entries = PathScanner.call() store.set(, [0, entries]) return entries end cached_mtime, entries = store.get() current_mtime = latest_mtime(, entries || []) return [] if current_mtime == -1 # path does not exist return entries if cached_mtime == current_mtime entries = PathScanner.call() store.set(, [current_mtime, entries]) entries end |
#expanded_path ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 81 def if @real path else ||= 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 |