Class: Dispatcher::CoreDispatcher

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

Overview

A core Dispatcher interface.

This is intended as a ‘virtual’ class that all other dispatcher interfaces inherit from.

Direct Known Subclasses

CGIDispatcher, CLIDispatcher

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(responder, *config) ⇒ CoreDispatcher

Creates a new



56
57
58
59
# File 'lib/dispatcher.rb', line 56

def initialize(responder, *config)
  @responder = responder
  @config    = config
end

Class Method Details

.inherited(subclass) ⇒ Object

Set the default_dispatcher to the last class that inherits CoreDispatcher.



79
80
81
# File 'lib/dispatcher.rb', line 79

def self.inherited(subclass)
  Dispatcher.default_dispatcher = subclass
end

Instance Method Details

#handle(request) ⇒ Object

Super-simple handler.

Just outputs any STDOUT content. Buffering should be done at the Responder level.



73
74
75
76
# File 'lib/dispatcher.rb', line 73

def handle(request)
  response = Response.new(@responder)
  response.render(request)
end

#listenObject

Start listening for incoming requests.

Raises:

  • (TypeError)


62
63
64
65
66
67
68
# File 'lib/dispatcher.rb', line 62

def listen
  err  = 'You are attempting to use the default Dispatcher interface. '
  err += 'Most likely the library was unable to autodetect an appropriate interface. '
  err += 'Try specifying one manually via a require \'request/<interface>\'.'
  
  raise TypeError, err, caller
end