simple_hot_folder 0.1.2 → 0.1.4
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 +4 -4
- data/.gitlab-ci.yml +33 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +11 -8
- data/Rakefile +13 -0
- data/lib/simple_hot_folder/hot_folder.rb +35 -20
- data/lib/simple_hot_folder/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46b8b20c55ab4f59864c93b7ade95d016678eeac
|
4
|
+
data.tar.gz: f2c6594371633b0e6513abd7dfa82d3f84dc597c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d8b895591e3d4285e6668438ffd606be35461c7533a7ba6f4ac9964e7cd062d36e4e82f38ff27ccc3912bee56953aa43f574b767c51bdc38a5061013db213e1
|
7
|
+
data.tar.gz: 05ece09a5a6626919fb966b55b2a6b4c8e9ee072811f75ac8f2e6247cd855650da11aa098942bbd144922384f44ade499d205477b238ec91f6838749194bf408
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Official language image. Look for the different tagged releases at:
|
2
|
+
# https://hub.docker.com/r/library/ruby/tags/
|
3
|
+
image: "ruby:2.4"
|
4
|
+
|
5
|
+
# Pick zero or more services to be used on all builds.
|
6
|
+
# Only needed when using a docker container to run your tests in.
|
7
|
+
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
|
8
|
+
# services:
|
9
|
+
# - mysql:latest
|
10
|
+
# - redis:latest
|
11
|
+
# - postgres:latest
|
12
|
+
|
13
|
+
# variables:
|
14
|
+
# POSTGRES_DB: database_name
|
15
|
+
|
16
|
+
# Cache gems in between builds
|
17
|
+
# cache:
|
18
|
+
# paths:
|
19
|
+
# - vendor/ruby
|
20
|
+
|
21
|
+
# This is a basic example for a gem or script which doesn't use
|
22
|
+
# services such as redis or postgres
|
23
|
+
before_script:
|
24
|
+
- ruby -v # Print out ruby version for debugging
|
25
|
+
# Uncomment next line if your rails app needs a JS runtime:
|
26
|
+
# - apt-get update -q && apt-get install nodejs -yqq
|
27
|
+
- gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image
|
28
|
+
# - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
29
|
+
- bundle install --path vendor
|
30
|
+
|
31
|
+
unit_tests:
|
32
|
+
script:
|
33
|
+
- rake test
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
[](https://badge.fury.io/rb/simple_hot_folder)
|
2
|
+
[](https://travis-ci.org/galfus/simple-hot-folder)
|
3
|
+
|
1
4
|
# Simple Hot Folder
|
2
5
|
|
3
6
|
### NOTE
|
4
7
|
|
5
|
-
This gem is at an early stage of development. Please do not use it already.
|
8
|
+
This gem is at an early stage of development. Please do not use it already.
|
6
9
|
|
7
10
|
|
8
11
|
## Install
|
@@ -23,16 +26,16 @@ hot_folder = SimpleHotFolder.for_files(
|
|
23
26
|
)
|
24
27
|
|
25
28
|
# Successful
|
26
|
-
hot_folder.process_input! do |
|
27
|
-
puts "Processing file #{
|
28
|
-
puts "File path: #{
|
29
|
-
puts "Now, the file is automatically
|
29
|
+
hot_folder.process_input! do |item|
|
30
|
+
puts "Processing file #{item.name}..."
|
31
|
+
puts "File path: #{item.path}"
|
32
|
+
puts "Now, the file is automatically deleted"
|
30
33
|
end
|
31
34
|
|
32
35
|
# On error
|
33
|
-
hot_folder.process_input! do |
|
34
|
-
puts "Processing file #{
|
35
|
-
puts "File path: #{
|
36
|
+
hot_folder.process_input! do |item|
|
37
|
+
puts "Processing file #{item.name}..."
|
38
|
+
puts "File path: #{item.path}"
|
36
39
|
puts "The file will be automatically moved to the error folder"
|
37
40
|
puts "A text file will be created with the error message ('Trigger error')"
|
38
41
|
puts "The process will continue with the next file"
|
data/Rakefile
CHANGED
@@ -87,12 +87,24 @@ task :release => :build do
|
|
87
87
|
if ask_for_confirmation != 'Y'
|
88
88
|
show_error_and_exit! "Aborting release"
|
89
89
|
end
|
90
|
+
puts ""
|
90
91
|
sh "git commit --allow-empty -m 'Release #{version}'"
|
91
92
|
sh "git tag v#{version}"
|
92
93
|
sh "git push origin master"
|
94
|
+
sh "git push github master"
|
93
95
|
show_release
|
94
96
|
end
|
95
97
|
|
98
|
+
desc "Push code to the remote respositories"
|
99
|
+
task :push do
|
100
|
+
show_text ">> Pushing code to GitLab y GitHub"
|
101
|
+
puts ""
|
102
|
+
sh "git push origin master"
|
103
|
+
puts ""
|
104
|
+
sh "git push github master"
|
105
|
+
puts ""
|
106
|
+
end
|
107
|
+
|
96
108
|
desc "Build #{gem_file} into pkg folder"
|
97
109
|
task :build do
|
98
110
|
show_text ">> Creating #{gem_file}"
|
@@ -105,6 +117,7 @@ end
|
|
105
117
|
desc "Publish #{gem_file} in RubyGems"
|
106
118
|
task :publish do
|
107
119
|
show_text ">> Publishing #{gem_file}"
|
120
|
+
puts ""
|
108
121
|
sh "gem push pkg/#{gem_file}"
|
109
122
|
puts ""
|
110
123
|
end
|
@@ -6,6 +6,12 @@ module SimpleHotFolder
|
|
6
6
|
'..',
|
7
7
|
]
|
8
8
|
|
9
|
+
# Create hot folder that listens for files.
|
10
|
+
#
|
11
|
+
# @param [String] input_path Input folder path
|
12
|
+
# @param [String] error_path Error folder path
|
13
|
+
# @param [String] output_path Error folder path
|
14
|
+
# @return [HotFolder]
|
9
15
|
def initialize(input_path, error_path, output_path)
|
10
16
|
@input_path = input_path
|
11
17
|
@error_path = error_path
|
@@ -13,46 +19,51 @@ module SimpleHotFolder
|
|
13
19
|
@validate_file = default_validate_file_function
|
14
20
|
end
|
15
21
|
|
22
|
+
# Yield a {Item} for each file/folder in the input path.
|
23
|
+
# Each file/folder is automatically deleted after the yield
|
24
|
+
# block is executed.
|
25
|
+
#
|
26
|
+
# @yieldparam [Item] item The file/folder.
|
16
27
|
def process_input!
|
17
28
|
entries = read_input(@input_path)
|
18
|
-
entries.each do |
|
29
|
+
entries.each do |item|
|
19
30
|
begin
|
20
|
-
yield
|
21
|
-
FileUtils.
|
31
|
+
yield item
|
32
|
+
FileUtils.rm(item.path) if File.exist?(item.path)
|
22
33
|
rescue Exception => e
|
23
|
-
move_file_to_error!(
|
34
|
+
move_file_to_error!(item, e)
|
24
35
|
end
|
25
36
|
end
|
26
37
|
end
|
27
38
|
|
28
39
|
private
|
29
40
|
|
30
|
-
def move_file_to_error!(
|
31
|
-
FileUtils.mv(
|
32
|
-
write_error_file(
|
41
|
+
def move_file_to_error!(item, exception)
|
42
|
+
FileUtils.mv(item.path, @error_path) if File.exist?(item.path)
|
43
|
+
write_error_file(item, exception.message)
|
33
44
|
end
|
34
45
|
|
35
|
-
def write_error_file(
|
36
|
-
path = "#{@error_path}/#{
|
46
|
+
def write_error_file(item, text)
|
47
|
+
path = "#{@error_path}/#{item.name}.txt"
|
37
48
|
File.open(path, 'w') { |file| file.write(text) }
|
38
49
|
end
|
39
50
|
|
40
51
|
def read_input(path)
|
41
52
|
Dir.entries(path)
|
42
|
-
.map { |name|
|
43
|
-
.keep_if { |
|
44
|
-
# .each { |
|
45
|
-
# .keep_if { |
|
53
|
+
.map { |name| Item.new(name, "#{path}/#{name}") }
|
54
|
+
.keep_if { |item| processable?(item) }
|
55
|
+
# .each { |item| p item.path }
|
56
|
+
# .keep_if { |item| @validate_file.(item) }
|
46
57
|
end
|
47
58
|
|
48
|
-
def
|
49
|
-
|
59
|
+
def validate_item(item)
|
60
|
+
item
|
50
61
|
end
|
51
62
|
|
52
|
-
def processable?(
|
53
|
-
return false if !File.file?(
|
54
|
-
return false if IGNORE_FOLDERS.include?(
|
55
|
-
return false if
|
63
|
+
def processable?(item)
|
64
|
+
return false if !File.file?(item.path)
|
65
|
+
return false if IGNORE_FOLDERS.include?(item.name)
|
66
|
+
return false if item.name.start_with?('.')
|
56
67
|
true
|
57
68
|
end
|
58
69
|
|
@@ -64,7 +75,11 @@ module SimpleHotFolder
|
|
64
75
|
|
65
76
|
end
|
66
77
|
|
67
|
-
|
78
|
+
# Each file or folder from the input folder.
|
79
|
+
#
|
80
|
+
# @param [String] name Name of the file/folder.
|
81
|
+
# @param [String] path Path of the file/folder.
|
82
|
+
class HotFolder::Item
|
68
83
|
attr_reader :name
|
69
84
|
attr_reader :path
|
70
85
|
def initialize(name, path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_hot_folder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,8 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".gitlab-ci.yml"
|
64
|
+
- ".travis.yml"
|
63
65
|
- CHANGELOG.md
|
64
66
|
- Gemfile
|
65
67
|
- README.md
|