Class: DeepCover::CustomRequirer::LoadPathsSubset
- Inherits:
-
Object
- Object
- DeepCover::CustomRequirer::LoadPathsSubset
- Defined in:
- lib/deep_cover/custom_requirer.rb
Instance Method Summary collapse
- #exist?(full_path) ⇒ Boolean
-
#initialize(load_paths: raise, lookup_paths: raise) ⇒ LoadPathsSubset
constructor
A new instance of LoadPathsSubset.
- #load_paths ⇒ Object
-
#potentially_within_lookup?(full_dir_path) ⇒ Boolean
E.g.
-
#within_lookup?(full_path) ⇒ Boolean
E.g.
Constructor Details
#initialize(load_paths: raise, lookup_paths: raise) ⇒ LoadPathsSubset
Returns a new instance of LoadPathsSubset.
8 9 10 11 12 13 |
# File 'lib/deep_cover/custom_requirer.rb', line 8 def initialize(load_paths: raise, lookup_paths: raise) @original_load_paths = load_paths @cached_load_paths_subset = [] @cached_load_paths_hash = nil @lookup_paths = lookup_paths.map { |p| File.(p) } end |
Instance Method Details
#exist?(full_path) ⇒ Boolean
33 34 35 |
# File 'lib/deep_cover/custom_requirer.rb', line 33 def exist?(full_path) within_lookup?(full_path) && File.exist?(full_path) end |
#load_paths ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/deep_cover/custom_requirer.rb', line 15 def load_paths if @cached_load_paths_hash != (h = @original_load_paths.hash) @cached_load_paths_subset = compute_subset @cached_load_paths_hash = h end @cached_load_paths_subset end |
#potentially_within_lookup?(full_dir_path) ⇒ Boolean
E.g. ‘/a/b/’ => true if a lookup path is ‘/a/b/c/’, because ‘/a/b/’ + ‘c/ok’ is within lookup.
24 25 26 |
# File 'lib/deep_cover/custom_requirer.rb', line 24 def potentially_within_lookup?(full_dir_path) @lookup_paths.any? { |p| p.start_with? full_dir_path } end |
#within_lookup?(full_path) ⇒ Boolean
E.g. ‘/a/b’ => true when a lookup path is ‘/a/’
29 30 31 |
# File 'lib/deep_cover/custom_requirer.rb', line 29 def within_lookup?(full_path) @lookup_paths.any? { |p| full_path.start_with? p } end |