file_scanner 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/README.md +21 -1
- data/lib/file_scanner/version.rb +1 -1
- data/lib/file_scanner/worker.rb +9 -2
- data/lib/file_scanner.rb +0 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c12f11f2f4e622c3b6004ea36c83e82e671e1395
|
4
|
+
data.tar.gz: 97d4d537ec6509e2f709afd9dfd17a0977b8cc9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6e038b6006fbbac3e25cfcf31277275b8046291c8557aee7f40cc92f554e392704014a57cdf29fca76c75ce6b9b8f2a1435b85348c5b9cd7c4947eead90ee27
|
7
|
+
data.tar.gz: 2bdf24965994cda568977723d6cbaafb8d3d19a49b78679233cc1a66327cc28db8b26753720ea57d2cae247ee4a1263b56c835491b64a2e9ca7b25d35407eddf
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
* [Worker](#worker)
|
12
12
|
* [Batches](#batches)
|
13
13
|
* [Logger](#logger)
|
14
|
+
* [Factory](#factory)
|
14
15
|
|
15
16
|
## Scope
|
16
17
|
This gem is aimed to collect a set of file paths starting by a wildcard rule, filter them by any default/custom filters (access time, matching name and size range) and apply a set of actions via a block call.
|
@@ -83,7 +84,7 @@ The `Worker` constructor accepts a `slice` attribute to give you a chance to dis
|
|
83
84
|
```ruby
|
84
85
|
worker = FileScanner::Worker.new(loader: loader, slice: 1000)
|
85
86
|
worker.call do |slice|
|
86
|
-
# perform action
|
87
|
+
# perform action 1000 paths per time
|
87
88
|
end
|
88
89
|
```
|
89
90
|
|
@@ -96,3 +97,22 @@ worker.call do |slice|
|
|
96
97
|
fail "Doh!" # will log error to my_file.log and re-raise exception
|
97
98
|
end
|
98
99
|
```
|
100
|
+
|
101
|
+
If you want to easily pass the same logger instance to the actions you are performing, it's available as the second argument of the block:
|
102
|
+
```ruby
|
103
|
+
require "fileutils"
|
104
|
+
|
105
|
+
worker.call do |slice, logger|
|
106
|
+
logger.info { "going to remove #{slice.size} files from disk!" }
|
107
|
+
FileUtils.rm_rf(slice)
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
#### Factory
|
112
|
+
You can create loader and worker instances at once by using the available factory:
|
113
|
+
```ruby
|
114
|
+
worker = FileScanner::Worker.factory(path: ENV["HOME"], extensions: %w[html txt], filters: filters, logger: my_logger, slice: 1000)
|
115
|
+
worker.call do |slice, logger|
|
116
|
+
# perform action 1000 paths per time
|
117
|
+
end
|
118
|
+
```
|
data/lib/file_scanner/version.rb
CHANGED
data/lib/file_scanner/worker.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
require "logger"
|
2
|
+
require "file_scanner/filters"
|
3
|
+
require "file_scanner/loader"
|
2
4
|
|
3
5
|
module FileScanner
|
4
6
|
class Worker
|
5
|
-
attr_reader :filters
|
6
|
-
|
7
7
|
def self.default_logger
|
8
8
|
Logger.new(nil).tap do |logger|
|
9
9
|
logger.level = Logger::ERROR
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.factory(path:, extensions: [], filters: [], logger: default_logger, slice: nil)
|
14
|
+
loader = Loader.new(path: path, extensions: extensions)
|
15
|
+
new(loader: loader, filters: filters, logger: logger, slice: slice)
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :loader, :filters
|
19
|
+
|
13
20
|
def initialize(loader:, filters: Filters::defaults, logger: self.class.default_logger, slice: nil)
|
14
21
|
@loader = loader
|
15
22
|
@filters = filters
|
data/lib/file_scanner.rb
CHANGED
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.0.
|
4
|
+
version: 2.0.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-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|