lib/file_scanner/worker.rb in file_scanner-3.0.1 vs lib/file_scanner/worker.rb in file_scanner-3.1.0
- old
+ new
@@ -12,15 +12,17 @@
def initialize(path:,
filters: Filters::defaults,
slice: SLICE,
all: false,
+ check: false,
logger: Logger.new(nil))
@path = File.expand_path(path)
@filters = filters
@slice = slice.to_i
@mode = mode(all)
+ @check = check
@logger = logger
end
def call
return slices unless block_given?
@@ -34,10 +36,15 @@
private def mode(all)
all ? ALL : ANY
end
+ private def valid?(file)
+ return true unless @check
+ FileTest.file?(file)
+ end
+
private def filter(file)
@filters.send(@mode) do |filter|
@logger.debug { "filtering by \e[33m#{@mode}\e[0m with \e[33m#{filter}\e[0m on #{File.basename(file)}" }
filter.call(file)
end
@@ -46,10 +53,10 @@
private def paths
Find.find(@path)
end
private def filtered
- paths.lazy.select { |file| filter(file) }
+ paths.lazy.select { |file| valid?(file) && filter(file) }
end
private def slices
filtered.each_slice(@slice)
end