Class: FayeRails::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/faye-rails/middleware.rb

Constant Summary collapse

DEFAULTS =
{
  :mount => '/faye',
  :timeout => 25,
  :extensions => nil,
  :engine => nil,
  :ping => nil,
  :server => 'thin'
}

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}, &block) ⇒ Middleware

Returns a new instance of Middleware.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/faye-rails/middleware.rb', line 13

def initialize(app, options={}, &block)
  @app = app

  if Rails.application.config.middleware.include? Rack::Lock
    message = "\nWARNING: You have the Rack::Lock middlware enabled.\n\nfaye-rails can't work when Rack::Lock is enabled, as it will cause\na deadlock on every request.\n\nPlease add:\n\nconfig.middleware.delete Rack::Lock\n\nto your application config in application.rb\n\n"
    Rails.logger.fatal message
    $stdout.puts message
    exit 1
  end

  unknown_options = options.keys - DEFAULTS.keys
  if unknown_options.one?
    raise ArgumentError, "Unknown option: #{unknown_options.first}."
  elsif unknown_options.any?
    raise ArgumentError, "Unknown options: #{unknown_options * ", "}."
  end

  options = DEFAULTS.merge(options)
  server = options.delete(:server)
  Faye::WebSocket.load_adapter(server) if server && server != 'passenger'

  @adapter = FayeRails::RackAdapter.new(@app, options)
  @adapter.instance_eval(&block) if block.respond_to? :call
end

Instance Method Details

#call(env) ⇒ Object


51
52
53
# File 'lib/faye-rails/middleware.rb', line 51

def call(env)
  @adapter.call(env)
end