class Riml::PathCache
Public Class Methods
new()
click to toggle source
# File lib/riml/path_cache.rb, line 3 def initialize @cache = {} end
Public Instance Methods
[](path)
click to toggle source
# File lib/riml/path_cache.rb, line 12 def [](path) path = normalize_path(path) @cache[path] end
[]=(path, val)
click to toggle source
# File lib/riml/path_cache.rb, line 7 def []=(path, val) path = normalize_path(path) @cache[path] = val end
cache(path)
click to toggle source
# File lib/riml/path_cache.rb, line 17 def cache(path) path = normalize_path(path) @cache[path] = {} path.each do |dir| files = Dir.glob(File.join(dir, '*')).to_a.select { |file| File.file?(file) } files.each do |full_path| basename = File.basename(full_path) # first file wins in PATH unless @cache[path][basename] @cache[path][basename] = full_path end end end end
clear()
click to toggle source
# File lib/riml/path_cache.rb, line 37 def clear @cache.clear end
file(path, basename)
click to toggle source
# File lib/riml/path_cache.rb, line 32 def file(path, basename) return nil unless @cache[path] @cache[path][basename] end
Private Instance Methods
normalize_path(path)
click to toggle source
returns array of strings (directory names in path)
# File lib/riml/path_cache.rb, line 44 def normalize_path(path) if path.is_a?(String) path.split(':') elsif path.respond_to?(:each) path else [path] end end