module WebSocket::ExceptionHandler::ClassMethods

Public Instance Methods

rescue_method(method_name, options = {}) click to toggle source

Rescue from WebSocket::Error errors.

@param [String] method_name Name of method that should be wrapped and rescued @param [Hash] options Options for rescue

@option options [Any] :return Value that should be returned instead of raised error

# File lib/websocket/exception_handler.rb, line 18
def rescue_method(method_name, options = {})
  define_method "#{method_name}_with_rescue" do |*args|
    begin
      send("#{method_name}_without_rescue", *args)
    rescue WebSocket::Error => e
      self.error = e.message.to_sym
      WebSocket.should_raise ? raise : options[:return]
    end
  end
  alias_method "#{method_name}_without_rescue", method_name
  alias_method method_name, "#{method_name}_with_rescue"
end