Class: Ftpd::ExceptionTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/ftpd/exception_translator.rb

Overview

Translate specific exceptions to FileSystemError.

This is not intended to be used directly, but via the TranslateExceptions module.

Instance Method Summary collapse

Constructor Details

#initializeExceptionTranslator

Returns a new instance of ExceptionTranslator.



12
13
14
# File 'lib/ftpd/exception_translator.rb', line 12

def initialize
  @exceptions = []
end

Instance Method Details

#register_exception(e) ⇒ Object

Register an exception class.



18
19
20
# File 'lib/ftpd/exception_translator.rb', line 18

def register_exception(e)
  @exceptions << e
end

#translate_exceptionsObject

Run a block, translating specific exceptions to FileSystemError.



24
25
26
27
28
29
30
# File 'lib/ftpd/exception_translator.rb', line 24

def translate_exceptions
  begin
    return yield
  rescue *@exceptions => e
    raise PermanentFileSystemError, e.message
  end
end