Class: Mediate::RequestHandler Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/mediate/request_handler.rb

Overview

This class is abstract.

override #handle to implement.

Abstract base class of a handler of requests. Each request type should have only one handler.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.handles(request_class, mediator = Mediate.mediator) ⇒ void

This method returns an undefined value.

Registers this handler for the given request Class.

The request Class must have Mediate::Request as a superclass.

Parameters:

  • request_class (Class)

    the Class of the requests that get passed to this handler

  • mediator (Mediate::Mediator) (defaults to: Mediate.mediator)

    the mediator instance to register the handler with

Raises:

  • (ArgumentError)

    if request_class does not inherit from Mediate::Request



22
23
24
# File 'lib/mediate/request_handler.rb', line 22

def self.handles(request_class, mediator = Mediate.mediator)
  mediator.register_request_handler(self, request_class)
end

Instance Method Details

#handle(_request) ⇒ Object

This method is abstract.

The method to implement that handles the request of the type registered for this handler. Whatever this method returns will be returned to the sender of the request.

Parameters:

Returns:

  • the result of handling the request

Raises:

  • (NoMethodError)


36
37
38
# File 'lib/mediate/request_handler.rb', line 36

def handle(_request)
  raise NoMethodError, "handle must be implemented"
end