Class: Evilution::LoadPath::SubpathResolver Private
- Inherits:
-
Object
- Object
- Evilution::LoadPath::SubpathResolver
- Defined in:
- lib/evilution/load_path/subpath_resolver.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.
Given an absolute (or expandable) file path, returns the shortest path
relative to any $LOAD_PATH entry the file lives under, or nil if the file
is outside every entry. The shortest match wins because a deeper LOAD_PATH
entry yields a shorter subpath that better matches require resolution.
Instance Method Summary collapse
- #call(file_path) ⇒ Object private
Instance Method Details
#call(file_path) ⇒ 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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/evilution/load_path/subpath_resolver.rb', line 10 def call(file_path) absolute = File.(file_path) best_subpath = nil $LOAD_PATH.each do |entry| dir = File.(entry) prefix = dir.end_with?("/") ? dir : "#{dir}/" next unless absolute.start_with?(prefix) candidate = absolute.delete_prefix(prefix) best_subpath = candidate if best_subpath.nil? || candidate.length < best_subpath.length end best_subpath end |