lib/file_scanner/worker.rb in file_scanner-2.2.1 vs lib/file_scanner/worker.rb in file_scanner-2.3.0

- old
+ new

@@ -2,21 +2,16 @@ require "file_scanner/filters" require "file_scanner/loader" module FileScanner class Worker - def self.factory(path:, extensions: [], filters: [], all: false, slice: nil, limit: -1, logger: Logger.new(nil)) - loader = Loader.new(path: path, extensions: extensions, limit: limit) - new(loader: loader, filters: filters, slice: slice, all: all, logger: logger) - end - attr_reader :loader, :filters def initialize(loader:, filters: Filters::defaults, all: false, slice: nil, logger: Logger.new(nil)) @loader = loader @filters = filters - @all = !!all + @mode = mode(all) @slice = slice.to_i @logger = logger end def call @@ -27,27 +22,21 @@ rescue StandardError => e @logger.error { e.message } raise e end - private def fetch_mode(mode) - return :any? unless @filters.respond_to?(mode) - mode - end - private def filtered - files = @loader.call - files.select! { |file| filter(file) } || files + @loader.call.select { |file| filter(file) } end - private def mode - return :all? if @all + private def mode(all) + return :all? if all :any? end private def filter(file) - @filters.send(mode) do |filter| - @logger.debug { "selecting by \e[33m#{mode}\e[0m with filter \e[33m#{filter}\e[0m on #{File.basename(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 end private def slices