file_scanner 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75a8147ed24cb8f74fb3eda35ead4c80ebb640ee
4
- data.tar.gz: 48eb06fdab9982b14efc09f5f35213e7f6552f24
3
+ metadata.gz: 5e94d61fa43f097a1912390317cde01b2119b997
4
+ data.tar.gz: 12a767ee4da87adf667e5cdee448e3f473a8a233
5
5
  SHA512:
6
- metadata.gz: 8f5d534a0122b1a124abfb65b554bdf185d08f43cf699964b1176c3e14e8942a44e88908acea04bcbbebe7167ebbb3163ab6640a4d3739c8006655752ec9c31c
7
- data.tar.gz: 75717028a39150d905fe3dd53abe0c6e8ab242b78f5020eea88c7bbf72a9cc5c3654cb563f4e301412b10c28dc0aab1f3445240bea5216b85390bf6960273173
6
+ metadata.gz: 526f96d30f7e39d148eaed24e90266ba44edfb1c509618691be479e66fda569e3d001903f9e05234fea0e60a4a7749b0d1bc0534fe125be9a1621357d9126388
7
+ data.tar.gz: 8c86dfc6a68ddd431a4656f7c833759f46717d89d8d89d967b0912de12505b562df93b3512474bbe111481c40b9eb810cf01e1f1d27b3966abb64a9617f5dc4f
data/README.md CHANGED
@@ -14,7 +14,6 @@
14
14
  * [Limit](#limit)
15
15
  * [Enumerator](#enumerator)
16
16
  * [Logger](#logger)
17
- * [Factory](#factory)
18
17
 
19
18
  ## Scope
20
19
  This gem is aimed to collect a set of file paths starting by a wildcard rule, filter them by any/all default/custom filters (access time, matching name and size range) and apply a set of actions via a block call.
@@ -132,12 +131,3 @@ worker.call do |slice, logger|
132
131
  FileUtils.rm_rf(slice)
133
132
  end
134
133
  ```
135
-
136
- #### Factory
137
- You can create loader and worker instances at once by using the available factory:
138
- ```ruby
139
- worker = FileScanner::Worker.factory(path: ENV["HOME"], extensions: %w[html txt], filters: filters, all: true, slice: 1000, limit: 6000, logger: my_logger)
140
- worker.call do |slice, logger|
141
- # filters applied on a maximum of 6000 paths, working a slice of 1000 files per time
142
- end
143
- ```
@@ -1,3 +1,3 @@
1
1
  module FileScanner
2
- VERSION = "2.2.1"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -4,17 +4,12 @@ require "file_scanner/loader"
4
4
 
5
5
  module FileScanner
6
6
  class Worker
7
- def self.factory(path:, extensions: [], filters: [], all: false, slice: nil, limit: -1, logger: Logger.new(nil))
8
- loader = Loader.new(path: path, extensions: extensions, limit: limit)
9
- new(loader: loader, filters: filters, slice: slice, all: all, logger: logger)
10
- end
11
-
12
7
  attr_reader :loader, :filters
13
8
 
14
9
  def initialize(loader:, filters: Filters::defaults, all: false, slice: nil, logger: Logger.new(nil))
15
10
  @loader = loader
16
11
  @filters = filters
17
- @all = !!all
12
+ @mode = mode(all)
18
13
  @slice = slice.to_i
19
14
  @logger = logger
20
15
  end
@@ -29,24 +24,18 @@ module FileScanner
29
24
  raise e
30
25
  end
31
26
 
32
- private def fetch_mode(mode)
33
- return :any? unless @filters.respond_to?(mode)
34
- mode
35
- end
36
-
37
27
  private def filtered
38
- files = @loader.call
39
- files.select! { |file| filter(file) } || files
28
+ @loader.call.select { |file| filter(file) }
40
29
  end
41
30
 
42
- private def mode
43
- return :all? if @all
31
+ private def mode(all)
32
+ return :all? if all
44
33
  :any?
45
34
  end
46
35
 
47
36
  private def filter(file)
48
- @filters.send(mode) do |filter|
49
- @logger.debug { "selecting by \e[33m#{mode}\e[0m with filter \e[33m#{filter}\e[0m on #{File.basename(file)}" }
37
+ @filters.send(@mode) do |filter|
38
+ @logger.debug { "filtering by \e[33m#{@mode}\e[0m with \e[33m#{filter}\e[0m on #{File.basename(file)}" }
50
39
  filter.call(file)
51
40
  end
52
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_scanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler