Class: RGen::Util::CachedGlob
- Inherits:
-
Object
- Object
- RGen::Util::CachedGlob
- Defined in:
- lib/rgen/util/cached_glob.rb
Overview
WARNING: the mechanism of taking timestamps of directories in order to find out if the content has changed doesn’t work reliably across all kinds of filesystems
Instance Method Summary collapse
-
#glob ⇒ Object
returns all files contained in directories matched by
dir_glob
which matchfile_glob
. -
#initialize(dir_glob, file_glob) ⇒ CachedGlob
constructor
A new instance of CachedGlob.
Constructor Details
#initialize(dir_glob, file_glob) ⇒ CachedGlob
Returns a new instance of CachedGlob.
10 11 12 13 14 15 16 17 |
# File 'lib/rgen/util/cached_glob.rb', line 10 def initialize(dir_glob, file_glob) @dir_glob = dir_glob @file_glob = file_glob @root_dirs = [] @dirs = {} @files = {} @timestamps = {} end |
Instance Method Details
#glob ⇒ Object
returns all files contained in directories matched by dir_glob
which match file_glob
. file_glob
must be relative to dir_glob
. dir_glob “*/a” with file_glob “*/.txt” is basically equivalent with Dir.glob(“/a/*/*.txt”) the idea is that the file glob will only be re-eavluated when the content of one of the directories matched by dir_glob has changed. this will only be faster than a normal Dir.glob if the number of dirs matched by dir_glob is relatively large and changes in files affect only a few of them at a time.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rgen/util/cached_glob.rb', line 26 def glob root_dirs = Dir.glob(@dir_glob) (@root_dirs - root_dirs).each do |d| remove_root_dir(d) end (@root_dirs & root_dirs).each do |d| update_root_dir(d) if dir_changed?(d) end (root_dirs - @root_dirs).each do |d| update_root_dir(d) end @root_dirs = root_dirs @root_dirs.sort.collect{|d| @files[d]}.flatten end |