Class: XmlConv::Util::PollingMission

Inherits:
Mission
  • Object
show all
Defined in:
lib/xmlconv/util/polling_manager.rb

Instance Attribute Summary collapse

Attributes inherited from Mission

#arguments, #backup_dir, #debug_recipients, #destination, #error_recipients, #filter, #partner, #postprocs, #reader, #tmp_destination, #writer

Instance Method Summary collapse

Methods inherited from Mission

#create_transaction, #filtered_transaction

Instance Attribute Details

#directoryObject

Returns the value of attribute directory.



41
42
43
# File 'lib/xmlconv/util/polling_manager.rb', line 41

def directory
  @directory
end

#glob_patternObject

Returns the value of attribute glob_pattern.



41
42
43
# File 'lib/xmlconv/util/polling_manager.rb', line 41

def glob_pattern
  @glob_pattern
end

Instance Method Details

#file_pathsObject



42
43
44
45
46
47
# File 'lib/xmlconv/util/polling_manager.rb', line 42

def file_paths
     path = File.expand_path(@glob_pattern || '*', @directory)
	Dir.glob(path).collect { |entry|
		File.expand_path(entry, @directory)
	}.compact
end

#pollObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/xmlconv/util/polling_manager.rb', line 48

def poll
     @directory = File.expand_path(@directory, CONFIG.project_root)
	file_paths.each { |path|
		begin
         filtered_transaction(File.read(path), 'file:' << path) { |transaction|
           yield transaction
         }
       rescue Exception => e
         puts e
         puts e.backtrace
		ensure
			FileUtils.mkdir_p(@backup_dir)
			FileUtils.mv(path, @backup_dir)
		end
	}
end