Class: SimpleHotFolder::HotFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_hot_folder/hot_folder.rb

Defined Under Namespace

Classes: Item

Constant Summary collapse

IGNORE_FOLDERS =
[
  '.',
  '..',
]

Instance Method Summary collapse

Constructor Details

#initialize(input_path, error_path, output_path) ⇒ HotFolder

Create hot folder that listens for files.

Parameters:

  • input_path (String)

    Input folder path

  • error_path (String)

    Error folder path

  • output_path (String)

    Error folder path



15
16
17
18
19
20
# File 'lib/simple_hot_folder/hot_folder.rb', line 15

def initialize(input_path, error_path, output_path)
  @input_path = input_path
  @error_path = error_path
  @output_path = output_path
  @validate_file = default_validate_file_function
end

Instance Method Details

#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.

Yield Parameters:

  • item (Item)

    The file/folder.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/simple_hot_folder/hot_folder.rb', line 27

def process_input!
  entries = read_input(@input_path)
  entries.each do |item|
    begin
      yield item
      FileUtils.rm(item.path) if File.exist?(item.path)
    rescue Exception => e
      move_file_to_error!(item, e)
    end
  end
end