file_scanner 3.1.0 → 3.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 478c7732cd0abb2981102eefe125cd22b9a20817
4
- data.tar.gz: 3e2b952a497d05a4922391e9cbcb8ece65547878
3
+ metadata.gz: 4603c0a4323560155dedb12615cb60ed38b81cf6
4
+ data.tar.gz: 7852a338f0f88218649424d36a464ec7488b2ef5
5
5
  SHA512:
6
- metadata.gz: 1dc2e81cec24ffde8024dc70b72afe8f4f749fbc911d2da201ec2129221852f66b98054ecc3e9767c32e7c75526bc7822018ce2bfaf9810ab4847d144c8093a5
7
- data.tar.gz: 80083baacc776549ecbe1575256459eba93bff72935b55428652ee42e8706d9e95b9a2dfd826f274dc29b685c4ffde6d90f1208e399f6bff013e2f4ca0904327
6
+ metadata.gz: 4b730537560c4060a437e03c81df4bb21838d7bbcbf13e80e41949f1591586cd7bdfbe6ea9577098b8de21b3c3b64f9699ddcbc6156000bcda414fdec1bdbae6
7
+ data.tar.gz: 7e93e56d4a2e3c760be967fcc8d92c4d7ab14c6c071d03989e94bccf43c248123a971ff012d8765261d9921ba3eb2546f3a71893a5f93d9186fa618f194d7a03
data/README.md CHANGED
@@ -9,16 +9,17 @@
9
9
  * [Custom](#custom)
10
10
  * [Worker](#worker)
11
11
  * [Enumerator](#enumerator)
12
- * [Block](#block)
12
+ * [Consuming results](#consuming-results)
13
13
  * [Mode](#mode)
14
14
  * [Check](#check)
15
15
  * [Logger](#logger)
16
16
 
17
17
  ## Scope
18
- This gem is aimed to collect a set of file paths starting by a wildcard rule, filter them by any/all default/custom filters (access time, matching name and size range) and apply a set of actions via a block call.
18
+ This gem is aimed to lazily collect a list of files by path and a set of filters.
19
19
 
20
20
  ## Motivation
21
- This gem is helpful to purge obsolete files or to promote relevant ones, by calling external services (CDN APIs) and/or local file system actions (copy, move, delete, etc).
21
+ This gem is helpful to purge obsolete files or to promote relevant ones, by calling external services (CDN APIs) and/or local file system actions (copy, move, delete, etc).
22
+ By working lazily, this library is aimed to work with a subset of large files list: just remember to apply a subset method to the final enumerator.
22
23
 
23
24
  ## Installation
24
25
  Add this line to your application's Gemfile:
@@ -65,19 +66,17 @@ filters << ->(file) { File.directory?(file) }
65
66
  The second step is to create the `Worker` instance by providing the path to scan and the list of filters to apply.
66
67
 
67
68
  #### Enumerator
68
- The `call` method of the worker return a lazy enumerator with the filtered elements, sliced by the specified number (default to 1000):
69
+ The `call` method of the worker return a lazy enumerator with the filtered elements:
69
70
  ```ruby
70
71
  worker = FileScanner::Worker.new(path: "~/Downloads", filters: filters, slice: 35)
71
72
  p worker.call
72
73
  => #<Enumerator::Lazy: ...
73
74
  ```
74
75
 
75
- #### Block
76
- To perform actions on each of the sliced paths just pass a block:
76
+ #### Consuming results
77
+ To leverage on the lazy behaviour remember to call a subset operator on the resulting enumerator:
77
78
  ```ruby
78
- worker.call do |slice|
79
- # perform actions on a slice of at max 35 elements
80
- end
79
+ worker.call.take(1000)
81
80
  ```
82
81
 
83
82
  #### Mode
@@ -101,17 +100,4 @@ If you dare to trace what the worker is doing (including errors), you can specif
101
100
  ```ruby
102
101
  my_logger = Logger.new("my_file.log")
103
102
  worker = FileScanner::Worker.new(loader: loader, logger: my_logger)
104
- worker.call do |slice|
105
- fail "Doh!" # will log error to my_file.log and re-raise exception
106
- end
107
- ```
108
-
109
- 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:
110
- ```ruby
111
- require "fileutils"
112
-
113
- worker.call do |slice, logger|
114
- logger.info { "going to remove #{slice.size} files from disk!" }
115
- FileUtils.rm_rf(slice)
116
- end
117
103
  ```
data/Rakefile CHANGED
@@ -7,4 +7,10 @@ Rake::TestTask.new(:spec) do |t|
7
7
  t.test_files = FileList["spec/**/*_spec.rb"]
8
8
  end
9
9
 
10
+ Rake::TestTask.new(:bench) do |t|
11
+ t.libs << "spec"
12
+ t.libs << "lib"
13
+ t.test_files = FileList["spec/**/*_bench.rb"]
14
+ end
15
+
10
16
  task :default => :spec
@@ -1,3 +1,3 @@
1
1
  module FileScanner
2
- VERSION = "3.1.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -4,7 +4,6 @@ require "file_scanner/filters"
4
4
 
5
5
  module FileScanner
6
6
  class Worker
7
- SLICE = 1000
8
7
  ALL = :all?
9
8
  ANY = :any?
10
9
 
@@ -12,23 +11,18 @@ module FileScanner
12
11
 
13
12
  def initialize(path:,
14
13
  filters: Filters::defaults,
15
- slice: SLICE,
16
14
  all: false,
17
15
  check: false,
18
16
  logger: Logger.new(nil))
19
17
  @path = File.expand_path(path)
20
18
  @filters = filters
21
- @slice = slice.to_i
22
19
  @mode = mode(all)
23
20
  @check = check
24
21
  @logger = logger
25
22
  end
26
23
 
27
24
  def call
28
- return slices unless block_given?
29
- slices.each do |slice|
30
- yield(slice, @logger)
31
- end
25
+ paths.lazy.select { |file| valid?(file) && filter(file) }
32
26
  rescue StandardError => e
33
27
  @logger.error { e.message }
34
28
  raise e
@@ -53,13 +47,5 @@ module FileScanner
53
47
  private def paths
54
48
  Find.find(@path)
55
49
  end
56
-
57
- private def filtered
58
- paths.lazy.select { |file| valid?(file) && filter(file) }
59
- end
60
-
61
- private def slices
62
- filtered.each_slice(@slice)
63
- end
64
50
  end
65
51
  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: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - costajob