Sha256: 7d7c43112fc61155b9c8d1a034ae3b3993a0e46926fdc0444f094933072c4da3

Contents?: true

Size: 797 Bytes

Versions: 1

Compression:

Stored size: 797 Bytes

Contents

module RestMan

  # :include: _doc/lib/restman/exceptions.rdoc
  module Exceptions
    # Map http status codes to the corresponding exception class
    EXCEPTIONS_MAP = {}
  end

  # Create HTTP status exception classes
  STATUSES.each_pair do |code, message|
    klass = Class.new(RequestFailed) do
      send(:define_method, :default_message) {"#{http_code ? "#{http_code} " : ''}#{message}"}
    end
    klass_constant = const_set(message.delete(' \-\''), klass)
    Exceptions::EXCEPTIONS_MAP[code] = klass_constant
  end

  # Create HTTP status exception classes used for backwards compatibility
  STATUSES_COMPATIBILITY.each_pair do |code, compat_list|
    klass = Exceptions::EXCEPTIONS_MAP.fetch(code)
    compat_list.each do |old_name|
      const_set(old_name, klass)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rest-man-1.1.0 lib/restman/exceptions/exceptions_map.rb