Class: BBMB::Util::FileMission
- Inherits:
-
Object
- Object
- BBMB::Util::FileMission
- Defined in:
- lib/bbmb/util/polling_manager.rb
Instance Attribute Summary collapse
-
#backup_dir ⇒ Object
Returns the value of attribute backup_dir.
-
#delete ⇒ Object
Returns the value of attribute delete.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
Instance Method Summary collapse
Instance Attribute Details
#backup_dir ⇒ Object
Returns the value of attribute backup_dir.
16 17 18 |
# File 'lib/bbmb/util/polling_manager.rb', line 16 def backup_dir @backup_dir end |
#delete ⇒ Object
Returns the value of attribute delete.
16 17 18 |
# File 'lib/bbmb/util/polling_manager.rb', line 16 def delete @delete end |
#directory ⇒ Object
Returns the value of attribute directory.
16 17 18 |
# File 'lib/bbmb/util/polling_manager.rb', line 16 def directory @directory end |
#glob_pattern ⇒ Object
Returns the value of attribute glob_pattern.
16 17 18 |
# File 'lib/bbmb/util/polling_manager.rb', line 16 def glob_pattern @glob_pattern end |
Instance Method Details
#file_paths ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/bbmb/util/polling_manager.rb', line 17 def file_paths path = File.(@glob_pattern || '*', @directory) res = Dir.glob(path).collect { |entry| File.(entry, @directory) }.compact res end |
#poll(&block) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/bbmb/util/polling_manager.rb', line 24 def poll(&block) @directory = File.(@directory, BBMB.config.bbmb_dir) unless File.directory?(@directory) && File.absolute_path(@directory) == @directory file_paths.each { |path| poll_path(path, &block) } end |
#poll_path(path, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bbmb/util/polling_manager.rb', line 31 def poll_path(path, &block) @backup_dir = BBMB.config.backup_dir if BBMB.config.respond_to?(:backup_dir) @backup_dir ||= Dir.tmpdir File.open(path) { |io| block.call(File.basename(path), io) } rescue StandardError => err BBMB::Util::Mail.notify_error(err) ensure if(@backup_dir) if File.absolute_path(@backup_dir) == @backup_dir dir = @backup_dir else dir = File.(@backup_dir, BBMB.config.bbmb_dir) end FileUtils.mkdir_p(dir) FileUtils.cp(path, dir) end if(@delete) FileUtils.rm(path) end end |