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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04135b6ae88b32be621d587dfa0ec5a9021062ff
4
- data.tar.gz: 87e4d6a63ac8febc2f106b32749d68f4a11848de
3
+ metadata.gz: c12f11f2f4e622c3b6004ea36c83e82e671e1395
4
+ data.tar.gz: 97d4d537ec6509e2f709afd9dfd17a0977b8cc9f
5
5
  SHA512:
6
- metadata.gz: bfc804f77a62758da9e32c6a472e254a008f2a7de736b965d6a94775b9311c73b833da4ce475bf06eeeefbf128d88467a00e647f1b500e90f555be9cb259125f
7
- data.tar.gz: 23418775678248e6f8e84a54c7dab42383af56efb9e88ee9b7fa92e1355d539fe7fa7ef353c91e159c24985bcad61b5f523e6e9bfbe3948436507eac30b73e37
6
+ metadata.gz: b6e038b6006fbbac3e25cfcf31277275b8046291c8557aee7f40cc92f554e392704014a57cdf29fca76c75ce6b9b8f2a1435b85348c5b9cd7c4947eead90ee27
7
+ data.tar.gz: 2bdf24965994cda568977723d6cbaafb8d3d19a49b78679233cc1a66327cc28db8b26753720ea57d2cae247ee4a1263b56c835491b64a2e9ca7b25d35407eddf
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /.edgerc
11
11
  /*.gem
12
+ /*.log
data/.travis.yml CHANGED
@@ -5,4 +5,4 @@ rvm:
5
5
  - 2.2.2
6
6
  - 2.3.0
7
7
  - 2.4.0
8
- before_install: gem install bundler -v 1.15.2
8
+ before_install: gem install bundler -v 1.15.3
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 on a slice of 1000 paths
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
+ ```
@@ -1,3 +1,3 @@
1
1
  module FileScanner
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -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
@@ -1,4 +1,2 @@
1
- require "file_scanner/filters"
2
- require "file_scanner/loader"
3
1
  require "file_scanner/version"
4
2
  require "file_scanner/worker"
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.1
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-09 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler