Permalink
Browse files

Diverge Metal implementation from Rack::Cascade since we want the las…

…t app to return its headers and body if the status is a 404.
  • Loading branch information...
1 parent c3f53f4 commit 12e416a04b764d0b212e04a53b770f60dc0d7071 @josh josh committed Dec 19, 2008
Showing with 22 additions and 44 deletions.
  1. +0 −31 railties/lib/rails/rack/cascade.rb
  2. +22 −13 railties/lib/rails/rack/metal.rb
@@ -1,31 +0,0 @@
-require 'active_support/ordered_hash'
-
-module Rails
- module Rack
- # Try a request on several apps; return the first non-404 response.
- class Cascade
- attr_reader :apps
-
- def initialize(apps)
- @apps = ActiveSupport::OrderedHash.new
- apps.each { |app| add app }
- end
-
- def call(env)
- @apps.keys.each do |app|
- result = app.call(env)
- return result unless result[0].to_i == 404
- end
- Metal::NotFoundResponse
- end
-
- def add(app)
- @apps[app] = true
- end
-
- def include?(app)
- @apps.include?(app)
- end
- end
- end
-end
@@ -1,26 +1,35 @@
-require 'rails/rack/cascade'
+require 'active_support/ordered_hash'
module Rails
module Rack
- module Metal
+ class Metal
NotFoundResponse = [404, {}, []].freeze
NotFound = lambda { NotFoundResponse }
- class << self
- def new(app)
- Cascade.new(builtins + [app])
+ def self.metals
+ base = "#{Rails.root}/app/metal"
+ matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/
+
+ Dir["#{base}/**/*.rb"].sort.map do |file|
+ file.sub!(matcher, '\1')
+ require file
+ file.classify.constantize
end
+ end
- def builtins
- base = "#{Rails.root}/app/metal"
- matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/
+ def initialize(app)
+ @app = app
+ @metals = ActiveSupport::OrderedHash.new
+ self.class.metals.each { |app| @metals[app] = true }
+ freeze
+ end
- Dir["#{base}/**/*.rb"].sort.map do |file|
- file.sub!(matcher, '\1')
- require file
- file.classify.constantize
- end
+ def call(env)
+ @metals.keys.each do |app|
+ result = app.call(env)
+ return result unless result[0].to_i == 404
end
+ @app.call(env)
end
end
end

0 comments on commit 12e416a

Please sign in to comment.