Sha256: 6dba8b22445b5d7601e39fc48c564f344fcd086513537c9fe4412aae18faf50c

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

module Ftpd

  # This module tranlates exceptions to FileSystemError exceptions.
  #
  # A disk file system (such as Ftpd::DiskFileSystem) is expected to
  # raise only FileSystemError exceptions, but many common operations
  # result in other exceptions such as SystemCallError.  This module
  # aids a disk driver in translating exceptions to FileSystemError
  # exceptions.
  #
  # In your file system, driver, include this module:
  #
  #     module MyDiskDriver
  #       include Ftpd::TranslateExceptions
  #
  # in your constructor, register the exceptions that should be translated:
  #
  #       def initialize
  #         translate_exception SystemCallError
  #       end
  #
  # And register methods for translation:
  #
  #       def read(ftp_path)
  #          ...
  #       end
  #       translate_exceptions :read

  module TranslateExceptions

    include Memoizer

    def self.included(includer)
      includer.extend ClassMethods
    end

    module ClassMethods

      # Cause the named method to translate exceptions.

      def translate_exceptions(method_name)
        original_method = instance_method(method_name)
        define_method method_name do |*args|
          exception_translator.translate_exceptions do
            original_method.bind(self).call *args
          end
        end
      end

    end

    # Add exception class e to the list of exceptions to be
    # translated.

    def translate_exception(e)
      exception_translator.register_exception e
    end

    private

    def exception_translator
      ExceptionTranslator.new
    end
    memoize :exception_translator

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ftpd-0.16.0 lib/ftpd/translate_exceptions.rb
ftpd-0.15.0 lib/ftpd/translate_exceptions.rb
ftpd-0.14.0 lib/ftpd/translate_exceptions.rb
ftpd-0.13.0 lib/ftpd/translate_exceptions.rb
ftpd-0.12.0 lib/ftpd/translate_exceptions.rb
ftpd-0.11.0 lib/ftpd/translate_exceptions.rb
ftpd-0.10.0 lib/ftpd/translate_exceptions.rb
ftpd-0.9.0 lib/ftpd/translate_exceptions.rb
ftpd-0.7.1 lib/ftpd/translate_exceptions.rb
ftpd-0.8.0 lib/ftpd/translate_exceptions.rb
ftpd-0.7.0 lib/ftpd/translate_exceptions.rb
ftpd-0.6.0 lib/ftpd/translate_exceptions.rb
ftpd-0.5.0 lib/ftpd/translate_exceptions.rb
ftpd-0.4.0 lib/ftpd/translate_exceptions.rb
ftpd-0.3.2 lib/ftpd/translate_exceptions.rb
ftpd-0.3.1 lib/ftpd/translate_exceptions.rb
ftpd-0.2.2 lib/ftpd/translate_exceptions.rb
ftpd-0.2.1 lib/ftpd/translate_exceptions.rb
ftpd-0.2.0 lib/ftpd/translate_exceptions.rb
ftpd-0.1.1 lib/ftpd/translate_exceptions.rb