multi-file-processor 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d5e14b48f52dce90cbc3181d383dddb84637200366205b6be219c358c42e84df
4
+ data.tar.gz: c7b5c86983d80195bef10041cc348a5aeee58613fccdcf53c1670077d015e05b
5
+ SHA512:
6
+ metadata.gz: cefbc9addea01a092fffdc5d2c7091e993d79baf1078ef1fb3bcdb4b90c25d49ae5a5ca81e167e5b296ee0fde6301be659402c81ed66f8a17fab1acb1a656721
7
+ data.tar.gz: f1f232ec0e9b1ea1fb08148ccc9231b7e08d8595ba7ee49addfab78da02ed76b5b59e81241bda0593e40afc126f62e3d0325f8fd647d1dc45f4c64e21611829f
@@ -0,0 +1,51 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ .DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ *~
39
+ \#*
40
+ .\#*
41
+
42
+ # For vim:
43
+ *.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+ *.gem
@@ -0,0 +1,19 @@
1
+ Style/HashEachMethods:
2
+ Enabled: true
3
+ Style/HashTransformKeys:
4
+ Enabled: true
5
+ Style/HashTransformValues:
6
+ Enabled: true
7
+ Style/ExpandPathArguments:
8
+ Enabled: false
9
+ Naming/FileName:
10
+ Enabled: false
11
+ Metrics/LineLength:
12
+ Max: 120
13
+ Metrics/ModuleLength:
14
+ Max: 120
15
+ Metrics/MethodLength:
16
+ Max: 20
17
+ AllCops:
18
+ Exclude:
19
+ - 'spec/**/*_spec.rb'
@@ -0,0 +1 @@
1
+ multi-file-processor
@@ -0,0 +1 @@
1
+ 2.6.5
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'rubocop'
8
+ end
9
+
10
+ group :spec do
11
+ gem 'rspec'
12
+ gem 'simplecov'
13
+ end
@@ -0,0 +1,52 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ast (2.4.0)
5
+ diff-lcs (1.3)
6
+ docile (1.3.2)
7
+ jaro_winkler (1.5.4)
8
+ parallel (1.19.1)
9
+ parser (2.7.0.5)
10
+ ast (~> 2.4.0)
11
+ rainbow (3.0.0)
12
+ rake (13.0.1)
13
+ rexml (3.2.4)
14
+ rspec (3.9.0)
15
+ rspec-core (~> 3.9.0)
16
+ rspec-expectations (~> 3.9.0)
17
+ rspec-mocks (~> 3.9.0)
18
+ rspec-core (3.9.1)
19
+ rspec-support (~> 3.9.1)
20
+ rspec-expectations (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-mocks (3.9.1)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-support (3.9.2)
27
+ rubocop (0.80.1)
28
+ jaro_winkler (~> 1.5.1)
29
+ parallel (~> 1.10)
30
+ parser (>= 2.7.0.1)
31
+ rainbow (>= 2.2.2, < 4.0)
32
+ rexml
33
+ ruby-progressbar (~> 1.7)
34
+ unicode-display_width (>= 1.4.0, < 1.7)
35
+ ruby-progressbar (1.10.1)
36
+ simplecov (0.18.5)
37
+ docile (~> 1.1)
38
+ simplecov-html (~> 0.11)
39
+ simplecov-html (0.12.2)
40
+ unicode-display_width (1.6.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ rake
47
+ rspec
48
+ rubocop
49
+ simplecov
50
+
51
+ BUNDLED WITH
52
+ 1.17.3
@@ -0,0 +1 @@
1
+ # multi-file-processor
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ # MultiFileProcessor processes files in a folder moving to the various states inprogress, done or failed.
6
+ class MultiFileProcessor
7
+ DEFAULT_INPROGRESS_EXT = 'inprogress'
8
+ DEFAULT_DONE_EXT = 'done'
9
+ DEFAULT_FAILED_EXT = 'failed'
10
+
11
+ class FailedException < StandardError; end
12
+
13
+ attr_reader :file_pattern,
14
+ :options
15
+
16
+ def initialize(file_pattern, options = {})
17
+ @file_pattern = file_pattern
18
+ @options = options
19
+ end
20
+
21
+ def each
22
+ while (inprogress_file = next_inprogress_file)
23
+ begin
24
+ yield inprogress_file
25
+ move_inprogress_file_to_done(inprogress_file)
26
+ rescue FailedException
27
+ move_inprogress_file_to_failed(inprogress_file)
28
+ end
29
+ end
30
+ end
31
+
32
+ # rubocop:disable Lint/SuppressedException
33
+ def next_inprogress_file
34
+ while (file = next_file)
35
+ begin
36
+ inprogress_file = "#{file}.#{inprogress_ext}"
37
+ FileUtils.mv(file, inprogress_file)
38
+ return inprogress_file
39
+ rescue Errno::ENOENT
40
+ end
41
+ end
42
+ end
43
+ # rubocop:enable Lint/SuppressedException
44
+
45
+ def move_inprogress_file_to_done(inprogress_file)
46
+ move_inprogress_file_to_ext(inprogress_file, done_ext)
47
+ end
48
+
49
+ def move_inprogress_file_to_failed(inprogress_file)
50
+ move_inprogress_file_to_ext(inprogress_file, failed_ext)
51
+ end
52
+
53
+ def reset_files!
54
+ ext_reg = Regexp.new("\\.(#{inprogress_ext}|#{done_ext}|#{failed_ext})$")
55
+ Dir.glob("#{file_pattern}.{#{inprogress_ext},#{done_ext},#{failed_ext}}").each do |file|
56
+ original_file = file.sub(ext_reg, '')
57
+ FileUtils.mv(file, original_file)
58
+ end
59
+ end
60
+
61
+ def failed!
62
+ raise FailedException, 'file processing failed'
63
+ end
64
+
65
+ def inprogress_ext
66
+ options[:inprogress_ext] || DEFAULT_INPROGRESS_EXT
67
+ end
68
+
69
+ def done_ext
70
+ options[:done_ext] || DEFAULT_DONE_EXT
71
+ end
72
+
73
+ def failed_ext
74
+ options[:failed_ext] || DEFAULT_FAILED_EXT
75
+ end
76
+
77
+ protected
78
+
79
+ def next_file
80
+ files = all_files
81
+ return files.sample if options[:sample]
82
+
83
+ files.sort! if options[:sort]
84
+ files = files.sort_by { |file| File.mtime(file) } if options[:sort_by_mtime]
85
+ files.first
86
+ end
87
+
88
+ private
89
+
90
+ def all_files
91
+ Dir.glob(file_pattern)
92
+ end
93
+
94
+ def move_inprogress_file_to_ext(inprogress_file, ext)
95
+ new_file = inprogress_file.sub(/#{inprogress_ext}$/, ext)
96
+ FileUtils.mv(inprogress_file, new_file)
97
+ end
98
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'multi-file-processor'
5
+ s.version = '0.1.0'
6
+ s.licenses = ['MIT']
7
+ s.summary = 'Process mutliple files'
8
+ s.description = 'Iterates over files moving them to inprogress, done or failed'
9
+ s.authors = ['Doug Youch']
10
+ s.email = 'dougyouch@gmail.com'
11
+ s.homepage = 'https://github.com/dougyouch/multi-file-processor'
12
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi-file-processor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doug Youch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Iterates over files moving them to inprogress, done or failed
14
+ email: dougyouch@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - ".rubocop.yml"
21
+ - ".ruby-gemset"
22
+ - ".ruby-version"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - README.md
26
+ - lib/multi-file-processor.rb
27
+ - multi-file-processor.gemspec
28
+ homepage: https://github.com/dougyouch/multi-file-processor
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.0.8
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Process mutliple files
51
+ test_files: []