Class: Rack::Stream::Handlers::AbstractHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/stream/handlers.rb

Overview

A handler instance is responsible for managing the opening, streaming, and closing for a particular protocol.

All handlers should inherit from AbstractHandler. Subclasses that inherit later have higher precedence than later subclassed handlers.

Direct Known Subclasses

EventSource, Http, WebSocket

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AbstractHandler

Returns a new instance of AbstractHandler.

Parameters:



35
36
37
38
# File 'lib/rack/stream/handlers.rb', line 35

def initialize(app)
  @app  = app
  @body = DeferrableBody.new
end

Class Attribute Details

.handlersObject (readonly)

Returns the value of attribute handlers.



20
21
22
# File 'lib/rack/stream/handlers.rb', line 20

def handlers
  @handlers
end

Class Method Details

.accepts?(app) ⇒ Boolean

Whether this handler knows how to handle a given request

Parameters:

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/rack/stream/handlers.rb', line 29

def accepts?(app)
  raise NotImplementedError
end

Instance Method Details

#chunk(*chunks) ⇒ Object

Enqueue content to be streamed at a later time.

Optionally override this method if you need to control the content at a protocol level.



44
45
46
# File 'lib/rack/stream/handlers.rb', line 44

def chunk(*chunks)
  @body.chunk(*chunks)
end

#closeObject

Implement #close for cleanup #close is called before the DeferrableBody is succeeded.



67
68
69
# File 'lib/rack/stream/handlers.rb', line 67

def close
  # do nothing
end

#openObject

Implement #open to initiate a connection

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/rack/stream/handlers.rb', line 55

def open
  raise NotImplementedError
end