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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5d628ab6d1c8b9f73a849e877a72e0524bf5560
4
- data.tar.gz: 461a54314b24ab407e58fc931e506fb92a24ae55
3
+ metadata.gz: 46b8b20c55ab4f59864c93b7ade95d016678eeac
4
+ data.tar.gz: f2c6594371633b0e6513abd7dfa82d3f84dc597c
5
5
  SHA512:
6
- metadata.gz: d8390e89d2d03a0fea0b116d8baf8922c50292263b68669c1d6c96dc14cb9e36b38f243296a154ae395ce756ce7be2796e498add73b825fbca1a4221fb10f9f8
7
- data.tar.gz: 5d844e412483647632b54aa63bc3ea460dfe89d6cbb0513edb17eca499885e3bc1e30520c71cbd3ed32328138e86f37a16daa62af61bba4b7c57eb4cb3cbc2b3
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
@@ -0,0 +1,11 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5
5
+ - 2.4
6
+ - 2.3
7
+ - 2.2
8
+ - 2.1
9
+ - 2.0
10
+ branches:
11
+ only: master
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.1.4] - 2018-07-13
6
+
7
+ * Delete current item from input folder after it has been processed.
8
+
9
+ ## [0.1.3] - 2018-07-12
10
+
11
+ * Travis configuration.
5
12
  * Gem description.
6
13
 
7
14
  ## [0.1.0] - 2018-07-10
data/Gemfile CHANGED
@@ -3,6 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in gtemplate.gemspec
4
4
  gemspec
5
5
 
6
- group :test do
6
+ group :test, :development do
7
7
  gem 'minitest-reporters'
8
8
  end
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
+ [![Gem Version](https://badge.fury.io/rb/simple_hot_folder.svg)](https://badge.fury.io/rb/simple_hot_folder)
2
+ [![Build Status](https://travis-ci.org/galfus/simple-hot-folder.svg?branch=master)](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 |entry|
27
- puts "Processing file #{entry.name}..."
28
- puts "File path: #{entry.path}"
29
- puts "Now, the file is automatically moved to the output folder"
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 |entry|
34
- puts "Processing file #{entry.name}..."
35
- puts "File path: #{entry.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 |entry|
29
+ entries.each do |item|
19
30
  begin
20
- yield entry
21
- FileUtils.mv(entry.path, @output_path) if File.exist?(entry.path)
31
+ yield item
32
+ FileUtils.rm(item.path) if File.exist?(item.path)
22
33
  rescue Exception => e
23
- move_file_to_error!(entry, e)
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!(entry, exception)
31
- FileUtils.mv(entry.path, @error_path) if File.exist?(entry.path)
32
- write_error_file(entry, exception.message)
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(entry, text)
36
- path = "#{@error_path}/#{entry.name}.txt"
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| Entry.new(name, "#{path}/#{name}") }
43
- .keep_if { |entry| processable?(entry) }
44
- # .each { |entry| p entry.path }
45
- # .keep_if { |entry| @validate_file.(entry) }
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 validate_entry(entry)
49
- entry
59
+ def validate_item(item)
60
+ item
50
61
  end
51
62
 
52
- def processable?(entry)
53
- return false if !File.file?(entry.path)
54
- return false if IGNORE_FOLDERS.include?(entry.name)
55
- return false if entry.name.start_with?('.')
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
- class HotFolder::Entry
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)
@@ -1,4 +1,4 @@
1
1
  module SimpleHotFolder
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  NAME = 'simple_hot_folder'.freeze
4
4
  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.2
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-10 00:00:00.000000000 Z
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