Class: Fingerprint::Scanner
- Inherits:
-
Object
- Object
- Fingerprint::Scanner
- Defined in:
- lib/fingerprint/scanner.rb
Overview
The scanner class can scan a set of directories and produce an index.
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
-
.scan_paths(paths, options = {}) ⇒ Object
A helper function to scan a set of directories.
Instance Method Summary collapse
-
#excluded?(path) ⇒ Boolean
Returns true if the given path should be excluded.
-
#initialize(roots, options = {}) ⇒ Scanner
constructor
Initialize the scanner to scan a given set of directories in order.
-
#scan ⇒ Object
Run the scanning process.
Constructor Details
#initialize(roots, options = {}) ⇒ Scanner
Initialize the scanner to scan a given set of directories in order.
options[:excludes]
-
An array of regular expressions of files to avoid indexing.
options[:output]
-
An
IO
where the results will be written.
35 36 37 38 39 40 41 42 |
# File 'lib/fingerprint/scanner.rb', line 35 def initialize(roots, = {}) @roots = roots @excludes = [:excludes] || DEFAULT_EXCLUDES @output = [:output] || StringIO.new @options = end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
44 45 46 |
# File 'lib/fingerprint/scanner.rb', line 44 def output @output end |
Class Method Details
Instance Method Details
#excluded?(path) ⇒ Boolean
Returns true if the given path should be excluded.
83 84 85 86 87 88 89 90 91 |
# File 'lib/fingerprint/scanner.rb', line 83 def excluded?(path) @excludes.each do |exclusion| if exclusion.match(path) return true end end return false end |
#scan ⇒ Object
Run the scanning process.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fingerprint/scanner.rb', line 94 def scan excluded_count = 0 checksummed_count = 0 directory_count = 0 @roots.each do |root| Dir.chdir(root) do output_header(root) Find.find("./") do |path| if File.directory?(path) if excluded?(path) excluded_count += 1 output_excluded(path) Find.prune # Ignore this directory else directory_count += 1 output_dir(path) end else unless excluded?(path) checksummed_count += 1 output_file(path) else excluded_count += 1 output_excluded(path) end end end end end # Output summary @output.puts "\# Directories: #{directory_count} Files: #{checksummed_count} Excluded: #{excluded_count}" end |