file_scanner 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -12
  3. data/lib/file_scanner/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb1ecb18e4ad80828cc4c294f551fd0382f35a36
4
- data.tar.gz: 8de6b0ee60c7d9dc239bd277e783ba268443cecd
3
+ metadata.gz: d3b3798bb1314d4039d0508aaf7e3a067dd35985
4
+ data.tar.gz: 82177994587d8288ba5650e9fdfd2bd72dfa46fa
5
5
  SHA512:
6
- metadata.gz: 7660c82c106d205c7dab1ca13e26b3a3692cb198c07b7343dff8f2c1daef989b3f6a802c3bda9a26aa88271fc859ebc29a956f5442627233493c2bae62375766
7
- data.tar.gz: c864ae94eb9853123e90c04ac9f7660f9ba1992fa2f8d8956c10a0bbf17ed3bfdd6bb54ffe423f266c5a7abddcaed4b2dfe3f5ac68e126c448fb56f918aabe76
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
- You can rely on existing filters that select files by:
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 default exist) to be applied to the list of filtered paths.
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
- This is exactly why the `Worker` class accept a `slice` attribute to distribute the work and avoid saturating the resources used by the specified policies:
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, filter: filter, policies: policies, slice: 1000)
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
- #### Policies by block
98
- In case you prefer to specify the policies as a block yielding the files slice, you can omit the `policies` argument at all:
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, filter: filter)
100
+ worker = FileScanner::Worker.new(loader: loader)
101
101
  worker.call do |slice|
102
- ->(slice) { FileUtils.chmod_R(0700, slice) }.call
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, filter: filter, logger: my_logger)
111
- worker.call # will log worker actions to my_file.log
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
  ```
@@ -1,3 +1,3 @@
1
1
  module FileScanner
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file_scanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob