file_scanner 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/file_scanner/version.rb +1 -1
- data/lib/file_scanner/worker.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 478c7732cd0abb2981102eefe125cd22b9a20817
|
4
|
+
data.tar.gz: 3e2b952a497d05a4922391e9cbcb8ece65547878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dc2e81cec24ffde8024dc70b72afe8f4f749fbc911d2da201ec2129221852f66b98054ecc3e9767c32e7c75526bc7822018ce2bfaf9810ab4847d144c8093a5
|
7
|
+
data.tar.gz: 80083baacc776549ecbe1575256459eba93bff72935b55428652ee42e8706d9e95b9a2dfd826f274dc29b685c4ffde6d90f1208e399f6bff013e2f4ca0904327
|
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
* [Enumerator](#enumerator)
|
12
12
|
* [Block](#block)
|
13
13
|
* [Mode](#mode)
|
14
|
+
* [Check](#check)
|
14
15
|
* [Logger](#logger)
|
15
16
|
|
16
17
|
## Scope
|
@@ -81,9 +82,18 @@ end
|
|
81
82
|
|
82
83
|
#### Mode
|
83
84
|
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.
|
84
|
-
In case you want restrict paths selection by all matching filters, just specify
|
85
|
+
In case you want restrict paths selection by all matching filters, just specify the `all` option:
|
85
86
|
```ruby
|
86
87
|
worker = FileScanner::Worker.new(loader: loader, filters: filters, all: true)
|
88
|
+
worker.call # will filter by applying all? predicate
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Check
|
92
|
+
By default the worker will scan for both directories and files.
|
93
|
+
In case you want restrict paths selection by files only, just specify the `check` option:
|
94
|
+
```ruby
|
95
|
+
worker = FileScanner::Worker.new(loader: loader, filters: filters, check: true)
|
96
|
+
worker.call # will skip directories
|
87
97
|
```
|
88
98
|
|
89
99
|
#### Logger
|
data/lib/file_scanner/version.rb
CHANGED
data/lib/file_scanner/worker.rb
CHANGED
@@ -14,11 +14,13 @@ module FileScanner
|
|
14
14
|
filters: Filters::defaults,
|
15
15
|
slice: SLICE,
|
16
16
|
all: false,
|
17
|
+
check: false,
|
17
18
|
logger: Logger.new(nil))
|
18
19
|
@path = File.expand_path(path)
|
19
20
|
@filters = filters
|
20
21
|
@slice = slice.to_i
|
21
22
|
@mode = mode(all)
|
23
|
+
@check = check
|
22
24
|
@logger = logger
|
23
25
|
end
|
24
26
|
|
@@ -36,6 +38,11 @@ module FileScanner
|
|
36
38
|
all ? ALL : ANY
|
37
39
|
end
|
38
40
|
|
41
|
+
private def valid?(file)
|
42
|
+
return true unless @check
|
43
|
+
FileTest.file?(file)
|
44
|
+
end
|
45
|
+
|
39
46
|
private def filter(file)
|
40
47
|
@filters.send(@mode) do |filter|
|
41
48
|
@logger.debug { "filtering by \e[33m#{@mode}\e[0m with \e[33m#{filter}\e[0m on #{File.basename(file)}" }
|
@@ -48,7 +55,7 @@ module FileScanner
|
|
48
55
|
end
|
49
56
|
|
50
57
|
private def filtered
|
51
|
-
paths.lazy.select { |file| filter(file) }
|
58
|
+
paths.lazy.select { |file| valid?(file) && filter(file) }
|
52
59
|
end
|
53
60
|
|
54
61
|
private def slices
|