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) ⇒ 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.
-
#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) ⇒ Path
Returns a new instance of Path.
23 24 25 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 23 def initialize(path) @path = path.to_s.freeze end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 21 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
.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 40 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
62 63 64 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 62 def File.(path).freeze end |
#non_directory? ⇒ Boolean
True if the path exists, but represents a non-directory object
28 29 30 31 32 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 28 def non_directory? !File.stat(path).directory? rescue Errno::ENOENT, Errno::ENOTDIR false end |
#relative? ⇒ Boolean
34 35 36 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 34 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.
10 11 12 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 10 def stable? stability == STABLE 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.
17 18 19 |
# File 'lib/bootsnap/load_path_cache/path.rb', line 17 def volatile? stability == VOLATILE end |