Sha256: cb78c85935762233d4a46b2e43c0da580b7656548fd6c05294e3618140b70c78

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

module FayeRails
  class Middleware

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

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

      if Rails.application.config.middleware.include? Rack::Lock
        message = <<-EOF

WARNING: You have the Rack::Lock middlware enabled.

faye-rails can't work when Rack::Lock is enabled, as it will cause
a deadlock on every request.

Please add:

    config.middleware.delete Rack::Lock

to your application config in application.rb

        EOF
        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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
faye-rails-2.0.3 lib/faye-rails/middleware.rb
faye-rails-2.0.1 lib/faye-rails/middleware.rb