simple_hot_folder 0.1.4 → 0.1.5

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: 46b8b20c55ab4f59864c93b7ade95d016678eeac
4
- data.tar.gz: f2c6594371633b0e6513abd7dfa82d3f84dc597c
3
+ metadata.gz: 309b622344dc4985cedfef8d20e50affe682406c
4
+ data.tar.gz: '01914ffa00e1d078a2b4f0803fdd41daec36f46b'
5
5
  SHA512:
6
- metadata.gz: 3d8b895591e3d4285e6668438ffd606be35461c7533a7ba6f4ac9964e7cd062d36e4e82f38ff27ccc3912bee56953aa43f574b767c51bdc38a5061013db213e1
7
- data.tar.gz: 05ece09a5a6626919fb966b55b2a6b4c8e9ee072811f75ac8f2e6247cd855650da11aa098942bbd144922384f44ade499d205477b238ec91f6838749194bf408
6
+ metadata.gz: 6ebd65347cee871f5a77c9664ed2cca2f922056e8a4a1d743a3b0d50ec7f66d79ae020290b36a549a521f0c30bfd50c898497efface934419b1604836235d1ae
7
+ data.tar.gz: bba02a8e15d15c7b0f4e4a688356674ab306d5af6eb94bf4e46791040e7fab1f695f44aa9a8d49022ae0f9a6a9910d5457e982036f2e49bdfd4918c9f7c13aa4
data/.gitlab-ci.yml CHANGED
@@ -1,33 +1,10 @@
1
- # Official language image. Look for the different tagged releases at:
2
- # https://hub.docker.com/r/library/ruby/tags/
3
1
  image: "ruby:2.4"
4
2
 
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
3
  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
4
+ - ruby -v
5
+ - gem install bundler --no-ri --no-rdoc
6
+ - bundle install
30
7
 
31
- unit_tests:
8
+ tests:
32
9
  script:
33
10
  - rake test
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.1.5] - 2018-07-15
6
+
7
+ * Remove `output_path`.
8
+ * Listen input folder.
9
+
5
10
  ## [0.1.4] - 2018-07-13
6
11
 
7
12
  * Delete current item from input folder after it has been processed.
data/README.md CHANGED
@@ -19,21 +19,27 @@ gem install simple_hot_folder
19
19
  ```ruby
20
20
  require 'simple_hot_folder'
21
21
 
22
+ # Create a hot folder that listens for files.
22
23
  hot_folder = SimpleHotFolder.for_files(
23
24
  '/path/to/input_folder',
24
- '/path/to/error_folder',
25
- '/path/to/output_folder'
25
+ '/path/to/error_folder'
26
26
  )
27
27
 
28
- # Successful
29
- hot_folder.process_input! do |item|
28
+ # Listen input folder for incomming files.
29
+ hot_folder.listen_input! do |item|
30
30
  puts "Processing file #{item.name}..."
31
31
  puts "File path: #{item.path}"
32
32
  puts "Now, the file is automatically deleted"
33
33
  end
34
34
 
35
+ # Stop listening.
36
+ hot_folder.listen_input! do |item|
37
+ puts "Processing file #{item.name}..."
38
+ hot_folder.stop_listening_after_this_item
39
+ end
40
+
35
41
  # On error
36
- hot_folder.process_input! do |item|
42
+ hot_folder.listen_input! do |item|
37
43
  puts "Processing file #{item.name}..."
38
44
  puts "File path: #{item.path}"
39
45
  puts "The file will be automatically moved to the error folder"
@@ -41,6 +47,11 @@ hot_folder.process_input! do |item|
41
47
  puts "The process will continue with the next file"
42
48
  raise 'Trigger error'
43
49
  end
50
+
51
+ # Process input folder just once.
52
+ hot_folder.process_input! do |item|
53
+ puts "Processing file #{item.name}..."
54
+ end
44
55
  ```
45
56
 
46
57
  ## License
data/Rakefile CHANGED
@@ -90,7 +90,9 @@ task :release => :build do
90
90
  puts ""
91
91
  sh "git commit --allow-empty -m 'Release #{version}'"
92
92
  sh "git tag v#{version}"
93
+ puts ""
93
94
  sh "git push origin master"
95
+ puts ""
94
96
  sh "git push github master"
95
97
  show_release
96
98
  end
@@ -10,13 +10,12 @@ module SimpleHotFolder
10
10
  #
11
11
  # @param [String] input_path Input folder path
12
12
  # @param [String] error_path Error folder path
13
- # @param [String] output_path Error folder path
14
13
  # @return [HotFolder]
15
- def initialize(input_path, error_path, output_path)
14
+ def initialize(input_path, error_path)
16
15
  @input_path = input_path
17
16
  @error_path = error_path
18
- @output_path = output_path
19
17
  @validate_file = default_validate_file_function
18
+ @stop = false
20
19
  end
21
20
 
22
21
  # Yield a {Item} for each file/folder in the input path.
@@ -28,6 +27,7 @@ module SimpleHotFolder
28
27
  entries = read_input(@input_path)
29
28
  entries.each do |item|
30
29
  begin
30
+ return if @stop
31
31
  yield item
32
32
  FileUtils.rm(item.path) if File.exist?(item.path)
33
33
  rescue Exception => e
@@ -36,6 +36,24 @@ module SimpleHotFolder
36
36
  end
37
37
  end
38
38
 
39
+ # Yield a {Item} for each file/folder in the input path.
40
+ # Each file/folder is automatically deleted after the yield
41
+ # block is executed.
42
+ #
43
+ # @yieldparam [Item] item The file/folder.
44
+ def listen_input!
45
+ while true
46
+ puts 'Listening...'
47
+ process_input! { |item| yield item }
48
+ return if @stop
49
+ sleep(1)
50
+ end
51
+ end
52
+
53
+ def stop_listening_after_this_item
54
+ @stop = true
55
+ end
56
+
39
57
  private
40
58
 
41
59
  def move_file_to_error!(item, exception)
@@ -1,4 +1,4 @@
1
1
  module SimpleHotFolder
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  NAME = 'simple_hot_folder'.freeze
4
4
  end
@@ -17,10 +17,9 @@ module SimpleHotFolder
17
17
  #
18
18
  # @param [String] input_path Input folder path
19
19
  # @param [String] error_path Error folder path
20
- # @param [String] output_path Error folder path
21
20
  # @return [HotFolder]
22
- def self.for_files(input_path, error_path, output_path = nil)
23
- HotFolder.new(input_path, error_path, output_path)
21
+ def self.for_files(input_path, error_path)
22
+ HotFolder.new(input_path, error_path)
24
23
  end
25
24
 
26
25
  end
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
4
+ version: 0.1.5
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-13 00:00:00.000000000 Z
11
+ date: 2018-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler