Sha256: 8cb7f1a8155af2a1045e1cc0db0aacc1a9638c948f8a8911743651f0f7664011

Contents?: true

Size: 771 Bytes

Versions: 51

Compression:

Stored size: 771 Bytes

Contents

module Rack
  # Rack::Cascade tries an request on several apps, and returns the
  # first response that is not 404 (or in a list of configurable
  # status codes).

  class Cascade
    NotFound = [404, {}, []]

    attr_reader :apps

    def initialize(apps, catch=404)
      @apps = []; @has_app = {}
      apps.each { |app| add app }

      @catch = {}
      [*catch].each { |status| @catch[status] = true }
    end

    def call(env)
      result = NotFound

      @apps.each do |app|
        result = app.call(env)
        break unless @catch.include?(result[0].to_i)
      end

      result
    end

    def add app
      @has_app[app] = true
      @apps << app
    end

    def include? app
      @has_app.include? app
    end

    alias_method :<<, :add
  end
end

Version data entries

51 entries across 48 versions & 15 rubygems

Version Path
kjvarga-rack-1.0.0 lib/rack/cascade.rb
qoobaa-rack-1.0.0.1 lib/rack/cascade.rb
qoobaa-rack-1.0.2 lib/rack/cascade.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rack-1.3.5/lib/rack/cascade.rb
candlepin-api-0.4.0 bundle/ruby/gems/rack-1.3.5/lib/rack/cascade.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rack-1.3.5/lib/rack/cascade.rb
rack-1.2.8 lib/rack/cascade.rb
rack-1.1.6 lib/rack/cascade.rb
rack-1.2.7 lib/rack/cascade.rb
rack-1.1.5 lib/rack/cascade.rb
rack-1.2.6 lib/rack/cascade.rb
rack-1.1.4 lib/rack/cascade.rb
radiant-1.0.0 ruby-debug/ruby/1.8/gems/rack-1.1.3/lib/rack/cascade.rb
rack-1.3.6 lib/rack/cascade.rb
rack-1.2.5 lib/rack/cascade.rb
rack-1.1.3 lib/rack/cascade.rb
rack-1.3.5 lib/rack/cascade.rb
rack-1.3.4 lib/rack/cascade.rb
vanity-1.7.1 vendor/ruby/1.9.1/gems/rack-1.1.2/lib/rack/cascade.rb
rack-1.2.4 lib/rack/cascade.rb