Class: Firehose::Rack::Consumer

Inherits:
Object
  • Object
show all
Defined in:
lib/firehose/rack/consumer.rb,
lib/firehose/rack/consumer/web_socket.rb,
lib/firehose/rack/consumer/http_long_poll.rb

Overview

Handles a subscription request over HTTP or WebSockets depeding on its abilities and binds that to the Firehose::Server::Subscription class, which is bound to a channel that gets published to.

Defined Under Namespace

Classes: HttpLongPoll, WebSocket

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Consumer

Let the client configure the consumer on initialization.

Yields:

  • (_self)

Yield Parameters:



14
15
16
# File 'lib/firehose/rack/consumer.rb', line 14

def initialize
  yield self if block_given?
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
# File 'lib/firehose/rack/consumer.rb', line 18

def call(env)
  websocket_request?(env) ? websocket.call(env) : http_long_poll.call(env)
end

#http_long_pollObject

Memoized instance of http long poll handler that can be configured from the rack app.



28
29
30
# File 'lib/firehose/rack/consumer.rb', line 28

def http_long_poll
  @http_long_poll ||= HttpLongPoll.new
end

#websocketObject

Memoized instance of web socket that can be configured from the rack app.



23
24
25
# File 'lib/firehose/rack/consumer.rb', line 23

def websocket
  @web_socket ||= WebSocket.new
end