file_scanner 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -12
- data/lib/file_scanner/version.rb +1 -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: d3b3798bb1314d4039d0508aaf7e3a067dd35985
|
4
|
+
data.tar.gz: 82177994587d8288ba5650e9fdfd2bd72dfa46fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 046f99929f5c43e475b5e4d8c6815712b112b3f0c873ef36257112fb17a06f37808e6985c1055ad35401543dc1c8cf50f0934211c20bee891beeba29051328b5
|
7
|
+
data.tar.gz: 734ddfae382c25e98e6bc2ff5bc9996c4f2ce083754a608ed93ae7ebed86aa7c7a73bbeb9fff4eb624c4d2306a621ef56b738370d5ee1aee5d22244946359c67
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ loader = FileScanner::Loader.new(path: ENV["HOME"], extensions: %w[html txt])
|
|
45
45
|
The second step is to provide the filters list to select files for which the `call` method is truthy.
|
46
46
|
|
47
47
|
#### Default
|
48
|
-
|
48
|
+
If you specify no filters the existing onee will select files by:
|
49
49
|
* checking if file is older than *30 days*
|
50
50
|
* checking if file size is *smaller than 100 bytes*
|
51
51
|
|
@@ -66,7 +66,7 @@ filters << ->(file) { File.directory?(file) }
|
|
66
66
|
```
|
67
67
|
|
68
68
|
### Policies
|
69
|
-
The third step is creating custom policies objects (no
|
69
|
+
The third step is creating custom policies objects (no defaults exist) to be applied to the list of filtered paths.
|
70
70
|
Again, it suffice the policy responds to the `call` method and accept an array of paths as an argument:
|
71
71
|
```ruby
|
72
72
|
require "fileutils"
|
@@ -87,19 +87,21 @@ worker.call # apply all the specified policies to the filtered file paths
|
|
87
87
|
```
|
88
88
|
|
89
89
|
#### Slice of files
|
90
|
-
In case you are going to scan a large number of files, is better to work in batches.
|
91
|
-
|
90
|
+
In case you are going to scan a large number of files, it is better to work in batches.
|
91
|
+
The `Worker` constructor accepts a `slice` attribute to better distribute loading (no sleep by default, use block syntax):
|
92
92
|
```ruby
|
93
|
-
worker = FileScanner::Worker.new(loader: loader,
|
94
|
-
worker.call # call policies by slice of 1000 files
|
93
|
+
worker = FileScanner::Worker.new(loader: loader, policies: policies, slice: 1000)
|
94
|
+
worker.call # call policies by slice of 1000 files with default filters
|
95
95
|
```
|
96
96
|
|
97
|
-
####
|
98
|
-
In case you prefer to specify the policies
|
97
|
+
#### Block syntax
|
98
|
+
In case you prefer to specify the policies inside a block for a more granular control on the slice of paths, you must omit the `policies` argument and use the block syntax:
|
99
99
|
```ruby
|
100
|
-
worker = FileScanner::Worker.new(loader: loader
|
100
|
+
worker = FileScanner::Worker.new(loader: loader)
|
101
101
|
worker.call do |slice|
|
102
|
-
->(slice) { FileUtils.chmod_R(0700, slice) }
|
102
|
+
policy = ->(slice) { FileUtils.chmod_R(0700, slice) }
|
103
|
+
policy.call
|
104
|
+
sleep 10 # wait 10 seconds before slurping next slice
|
103
105
|
end
|
104
106
|
```
|
105
107
|
|
@@ -107,6 +109,8 @@ end
|
|
107
109
|
If you dare to trace what the worker is doing (including errors), you can specify a logger to the worker class:
|
108
110
|
```ruby
|
109
111
|
my_logger = Logger.new("my_file.log")
|
110
|
-
worker = FileScanner::Worker.new(loader: loader,
|
111
|
-
worker.call
|
112
|
+
worker = FileScanner::Worker.new(loader: loader, logger: my_logger)
|
113
|
+
worker.call do |slice|
|
114
|
+
fail "Doh!" # will log error to my_file.log and re-raise exception
|
115
|
+
end
|
112
116
|
```
|
data/lib/file_scanner/version.rb
CHANGED