file_scanner 3.2.1 → 3.2.2

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: eb4e842377393a5dcea9c34c6de8407a51399605
4
- data.tar.gz: 9fc5acff042a51db73d9cd7a069e4340acde3f29
3
+ metadata.gz: 06a7dc00a6fc9f3a0c04dd86e9a412478b339cb7
4
+ data.tar.gz: 97d28bee119ac7f840e1c55c4f9872b33e679e2f
5
5
  SHA512:
6
- metadata.gz: 45322898db24dcd13bda1488137769f4e0a5eb14aab8c6af1acb8f1fb0823cb7fcf5003fdfee05e454a547fcb735fa8372a5ade7c666b38a7694324c8c70e41b
7
- data.tar.gz: ce70343fa5ccd3eb8521de6c2fb9c07c572c52655958b8dce36809e0f97cdb2bba055e7ca484bcfa2bdc4d2582e328f818ca8c0f10ca4f29d01d7bd5ab2b4525
6
+ metadata.gz: e42a649dcbe3b49b3bd3c13ba3dae2c9ba7e7a3cdeb4e1294a8951c07071e62415bdb554faa581f4e70d2b1422a4206f47ec48bed5dee8bc981d106228bb5311
7
+ data.tar.gz: 0ec10cadb7c8d9688ac98e02f9d8a4bb1c7389e5ba468da420e16970cd571b0f504fdd99c1d9cd255030ddb82b279855213b0000440e605d8e54ee24e89e5b70
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  * [Enumerator](#enumerator)
12
12
  * [Consuming results](#consuming-results)
13
13
  * [Mode](#mode)
14
- * [Check](#check)
14
+ * [File check](#file-check)
15
15
  * [Logger](#logger)
16
16
 
17
17
  ## Scope
@@ -48,7 +48,7 @@ If you specify no filters the default ones are loaded, selecting files by:
48
48
  * checking if file size is within *0KB and 5KB*
49
49
  * checking if file *basename matches* the specified *regexp* (if any)
50
50
 
51
- You can update default filters behaviours by passing custom arguments:
51
+ You can update default filters behaviour by passing custom arguments:
52
52
  ```ruby
53
53
  a_week_ago = FileScanner::Filters::LastAccess.new(Time.now-7*24*3600)
54
54
  one_two_mb = FileScanner::Filters::SizeRange.new(min: 1024**2, max: 2*1024**2)
@@ -74,25 +74,27 @@ p worker.call
74
74
  ```
75
75
 
76
76
  #### Consuming results
77
- To leverage on the lazy behaviour remember to call a subset operator on the resulting enumerator:
77
+ To leverage on the lazy behaviour remember to call a subset method on the resulting enumerator:
78
78
  ```ruby
79
- worker.call.take(1000)
79
+ worker.call.take(1000).each do |file|
80
+ # perform action on filtered files
81
+ end
80
82
  ```
81
83
 
82
84
  #### Mode
83
- By default the worker will select paths by applying any of the matching filters: this is it, it suffice just one of the specified filters to be true to grab the path.
85
+ By default the worker does select paths by applying any of the matching filters: it suffice just one of the filters to match to grab the path.
84
86
  In case you want restrict paths selection by all matching filters, just specify the `all` option:
85
87
  ```ruby
86
88
  worker = FileScanner::Worker.new(loader: loader, filters: filters, all: true)
87
89
  worker.call # will filter by applying all? predicate
88
90
  ```
89
91
 
90
- #### Check
91
- By default the worker will scan for both directories and files.
92
- In case you want restrict paths selection by files only, just specify the `check` option:
92
+ #### File check
93
+ By default the worker does collect both directories and files.
94
+ In case you want restrict selction by files only, just specify the `filecheck` option:
93
95
  ```ruby
94
- worker = FileScanner::Worker.new(loader: loader, filters: filters, check: true)
95
- worker.call # will skip directories
96
+ worker = FileScanner::Worker.new(loader: loader, filters: filters, filecheck: true)
97
+ worker.call # skip directories
96
98
  ```
97
99
 
98
100
  #### Logger
@@ -1,3 +1,3 @@
1
1
  module FileScanner
2
- VERSION = "3.2.1"
2
+ VERSION = "3.2.2"
3
3
  end
@@ -12,16 +12,17 @@ module FileScanner
12
12
  def initialize(path:,
13
13
  filters: Filters::defaults,
14
14
  all: false,
15
- check: false,
15
+ filecheck: false,
16
16
  logger: Logger.new(nil))
17
17
  @path = File.expand_path(path)
18
18
  @filters = filters
19
19
  @mode = mode(all)
20
- @check = check
20
+ @filecheck = filecheck
21
21
  @logger = logger
22
22
  end
23
23
 
24
24
  def call
25
+ @logger.debug { "skipping directories" } if @filecheck
25
26
  paths.lazy.select { |file| valid?(file) && filter(file) }
26
27
  rescue StandardError => e
27
28
  @logger.error { e.message }
@@ -33,13 +34,14 @@ module FileScanner
33
34
  end
34
35
 
35
36
  private def valid?(file)
36
- return true unless @check
37
+ return true unless @filecheck
37
38
  FileTest.file?(file)
38
39
  end
39
40
 
40
41
  private def filter(file)
42
+ @logger.debug { "filters applied by \e[35m#{@mode}\e[0m" }
41
43
  @filters.send(@mode) do |filter|
42
- @logger.debug { "filtering by \e[33m#{@mode}\e[0m with \e[33m#{filter}\e[0m on #{File.basename(file)}" }
44
+ @logger.debug { "filtering on \e[33m#{File.basename(file)}\e[0m" }
43
45
  filter.call(file)
44
46
  end
45
47
  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: 3.2.1
4
+ version: 3.2.2
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-25 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler