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.


10
11
12
# File 'lib/ftpd/exception_translator.rb', line 10

def initialize
  @exceptions = []
end

Instance Method Details

#register_exception(e) ⇒ Object

Register an exception class.


16
17
18
# File 'lib/ftpd/exception_translator.rb', line 16

def register_exception(e)
  @exceptions << e
end

#translate_exceptionsObject

Run a block, translating specific exceptions to FileSystemError.


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

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