Class: RServiceBus::Monitor_DirNotifier
- Defined in:
- lib/rservicebus/Monitor/DirNotifier.rb
Instance Attribute Summary collapse
-
#Filter ⇒ Object
readonly
Returns the value of attribute Filter.
-
#Path ⇒ Object
readonly
Returns the value of attribute Path.
-
#ProcessingFolder ⇒ Object
readonly
Returns the value of attribute ProcessingFolder.
Attributes inherited from Monitor
Instance Method Summary collapse
- #connect(uri) ⇒ Object
- #file_writable?(path) ⇒ Boolean
- #get_files ⇒ Object
- #Look ⇒ Object
- #move_file(src, dest) ⇒ Object
- #open_folder(path) ⇒ Object
Methods inherited from Monitor
#_connect, #finished, #initialize, #reconnect, #send
Constructor Details
This class inherits a constructor from RServiceBus::Monitor
Instance Attribute Details
#Filter ⇒ Object (readonly)
Returns the value of attribute Filter.
9 10 11 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 9 def Filter @Filter end |
#Path ⇒ Object (readonly)
Returns the value of attribute Path.
9 10 11 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 9 def Path @Path end |
#ProcessingFolder ⇒ Object (readonly)
Returns the value of attribute ProcessingFolder.
9 10 11 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 9 def ProcessingFolder @ProcessingFolder end |
Instance Method Details
#connect(uri) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 11 def connect(uri) #Pass the path through the Dir object to check syntax on startup begin self.open_folder uri.path unless self.file_writable?(uri.path) then puts "***** Directory is not writable, #{uri.path}." puts "***** Make the directory, #{uri.path}, writable and try again." abort() end rescue Errno::ENOENT => e puts "***** Directory does not exist, #{uri.path}." puts "***** Create the directory, #{uri.path}, and try again." puts "***** eg, mkdir #{uri.path}" abort() rescue Errno::ENOTDIR => e puts "***** The specified path does not point to a directory, #{uri.path}." puts "***** Either repoint path to a directory, or remove, #{uri.path}, and create it as a directory." puts "***** eg, rm #{uri.path} && mkdir #{uri.path}" abort() end @Path = uri.path if uri.query.nil? puts '***** Processing Directory is not specified.' puts '***** Specify the Processing Directory as a query string in the Path URI' puts "***** eg, '/#{uri.path}?processing=*ProcessingDir*" abort() else parts = CGI.parse(uri.query) if parts.has_key? 'processing' then processingUri = URI.parse parts['processing'][0] begin self.open_folder processingUri.path unless self.file_writable?(processingUri.path) then puts "***** Processing Directory is not writable, #{processingUri.path}." puts "***** Make the directory, #{processingUri.path}, writable and try again." abort() end rescue Errno::ENOENT => e puts "***** Processing Directory does not exist, #{processingUri.path}." puts "***** Create the directory, #{processingUri.path}, and try again." puts "***** eg, mkdir #{processingUri.path}" abort() rescue Errno::ENOTDIR => e puts "***** Processing Directory does not point to a directory, #{processingUri.path}." puts "***** Either repoint path to a directory, or remove, #{processingUri.path}, and create it as a directory." puts "***** eg, rm #{processingUri.path} && mkdir #{processingUri.path}" abort() end @ProcessingFolder = processingUri.path end @Filter = '*' if parts.has_key? 'filter' then @Filter = parts['filter'][0] end end end |
#file_writable?(path) ⇒ Boolean
81 82 83 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 81 def file_writable? path return File.writable? path end |
#get_files ⇒ Object
95 96 97 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 95 def get_files return Dir.glob( Pathname.new("#{@Path}").join(@Filter) ).select { |f| File.file?(f) } end |
#Look ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 73 def Look fileList = self.get_files fileList.each do |filePath| newPath = self.move_file(filePath, @ProcessingFolder) self.send( nil, URI.parse( "file://#{newPath}" ) ) end end |
#move_file(src, dest) ⇒ Object
89 90 91 92 93 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 89 def move_file src, dest FileUtils.mv(src, dest) filename = Pathname.new(src).basename return Pathname.new(dest).join(filename) end |
#open_folder(path) ⇒ Object
85 86 87 |
# File 'lib/rservicebus/Monitor/DirNotifier.rb', line 85 def open_folder path Dir.new path end |