Class: FileScanner::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/file_scanner/worker.rb

Constant Summary collapse

ALL =
:all?
ANY =
:any?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, filters: Filters::defaults, all: false, filecheck: false, logger: Logger.new(nil)) ⇒ Worker

Returns a new instance of Worker.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/file_scanner/worker.rb', line 12

def initialize(path:, 
               filters: Filters::defaults, 
               all: false, 
               filecheck: false,
               logger: Logger.new(nil))
  @path = File.expand_path(path) << File::SEPARATOR
  @filters = filters
  @mode = mode(all)
  @filecheck = filecheck
  @logger = logger
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



10
11
12
# File 'lib/file_scanner/worker.rb', line 10

def filters
  @filters
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/file_scanner/worker.rb', line 10

def path
  @path
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
# File 'lib/file_scanner/worker.rb', line 24

def call
  @logger.info { "scanning \e[1m#{@path}\e[0m..." }
  @logger.debug { "skipping directories" } if @filecheck
  @logger.debug { "applying \e[36m#{@filters.size}\e[0m filters by \e[35m#{@mode}\e[0m" }
  paths.lazy.select { |file| valid?(file) && filter(file) }
rescue StandardError => e
  @logger.error { e.message }
  raise e
end