Class: DeepCover::CustomRequirer::LoadPathsSubset

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_cover/custom_requirer.rb

Instance Method Summary collapse

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.expand_path(p) }
end

Instance Method Details

#exist?(full_path) ⇒ Boolean

Returns:

  • (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_pathsObject



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.

Returns:

  • (Boolean)


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/’

Returns:

  • (Boolean)


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