class DirectoryWatcher::Scan
A Scan is the scan of a full directory structure with the ability to iterate over the results, or return them as a full dataset
results = Scan.new( globs ).run
Public Class Methods
new( globs = Array.new )
click to toggle source
# File lib/directory_watcher/scan.rb, line 8 def initialize( globs = Array.new ) @globs = [ globs ].flatten @results = Array.new end
Public Instance Methods
results()
click to toggle source
Return the results of the scan. If the scan has not been run yet, then run it
# File lib/directory_watcher/scan.rb, line 23 def results @results = collect_all_stats if @results.empty? return @results end
run()
click to toggle source
Run the entire scan and collect all the results. The Scan will only ever be run once.
Return the array of FileStat results
# File lib/directory_watcher/scan.rb, line 17 def run results end
Private Instance Methods
collect_all_stats()
click to toggle source
Collect all the Stats into an Array and return them
# File lib/directory_watcher/scan.rb, line 34 def collect_all_stats r = [] each { |stat| r << stat } return r end
each( ) { |stat| ... }
click to toggle source
Iterate over each item that matches the glob. The item yielded is a ::DirectoryWatcher::FileStat object.
# File lib/directory_watcher/scan.rb, line 51 def each( &block ) each_glob do |glob| Dir.glob(glob).each do |fn| if stat = file_stat( fn ) then yield stat if block_given? end end end end
each_glob( ) { |glob| ... }
click to toggle source
Iterate over each glob, yielding it
# File lib/directory_watcher/scan.rb, line 42 def each_glob( &block ) @globs.each do |glob| yield glob end end
file_stat( fn, if_not_file = false )
click to toggle source
Return the stat of of the file in question. If the item is not a file, then
return the value of the passed in if_not_file
# File lib/directory_watcher/scan.rb, line 64 def file_stat( fn, if_not_file = false ) stat = File.stat fn return if_not_file unless stat.file? return DirectoryWatcher::FileStat.new( fn, stat.mtime, stat.size ) rescue SystemCallError => e # swallow $stderr.puts "Error Stating #{fn} : #{e}" end