Class: SimpleHotFolder::HotFolder
- Inherits:
-
Object
- Object
- SimpleHotFolder::HotFolder
- Defined in:
- lib/simple_hot_folder/hot_folder.rb
Defined Under Namespace
Classes: Item
Constant Summary collapse
- IGNORE_FOLDERS =
[ '.', '..', ]
Instance Method Summary collapse
-
#initialize(input_path, error_path) ⇒ HotFolder
constructor
Create hot folder that listens for files.
-
#listen_input! {|item| ... } ⇒ Object
Yield a Item for each file/folder in the input path.
-
#process_input! {|item| ... } ⇒ Object
Yield a Item for each file/folder in the input path.
- #stop_listening_after_this_item ⇒ Object
Constructor Details
#initialize(input_path, error_path) ⇒ HotFolder
Create hot folder that listens for files.
14 15 16 17 18 19 |
# File 'lib/simple_hot_folder/hot_folder.rb', line 14 def initialize(input_path, error_path) @input_path = input_path @error_path = error_path @validate_file = default_validate_file_function @stop = false end |
Instance Method Details
#listen_input! {|item| ... } ⇒ Object
Yield a Item for each file/folder in the input path. Each file/folder is automatically deleted after the yield block is executed.
44 45 46 47 48 49 50 |
# File 'lib/simple_hot_folder/hot_folder.rb', line 44 def listen_input! while true process_input! { |item| yield item } return if @stop sleep(1) end end |
#process_input! {|item| ... } ⇒ Object
Yield a Item for each file/folder in the input path. Each file/folder is automatically deleted after the yield block is executed.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/simple_hot_folder/hot_folder.rb', line 26 def process_input! entries = read_input(@input_path) entries.each do |item| begin return if @stop yield item FileUtils.rm(item.path) if File.exist?(item.path) rescue Exception => e move_file_to_error!(item, e) end end end |
#stop_listening_after_this_item ⇒ Object
52 53 54 |
# File 'lib/simple_hot_folder/hot_folder.rb', line 52 def stop_listening_after_this_item @stop = true end |