aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-12-19 11:04:27 -0600
committerJoshua Peek <josh@joshpeek.com>2008-12-19 11:07:25 -0600
commit12e416a04b764d0b212e04a53b770f60dc0d7071 (patch)
tree7f1ef6c1357ea1353dc4e919557b0779983dfda1
parentc3f53f412cd170fc295b46e48aa81837ad15ec83 (diff)
downloadrails-12e416a04b764d0b212e04a53b770f60dc0d7071.tar.gz
rails-12e416a04b764d0b212e04a53b770f60dc0d7071.tar.bz2
rails-12e416a04b764d0b212e04a53b770f60dc0d7071.zip
Diverge Metal implementation from Rack::Cascade since we want the last app to return its headers and body if the status is a 404.
-rw-r--r--railties/lib/rails/rack/cascade.rb31
-rw-r--r--railties/lib/rails/rack/metal.rb35
2 files changed, 22 insertions, 44 deletions
diff --git a/railties/lib/rails/rack/cascade.rb b/railties/lib/rails/rack/cascade.rb
deleted file mode 100644
index d5af7fc77e..0000000000
--- a/railties/lib/rails/rack/cascade.rb
+++ /dev/null
@@ -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
diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb
index 1df31a1594..b185227234 100644
--- a/railties/lib/rails/rack/metal.rb
+++ b/railties/lib/rails/rack/metal.rb
@@ -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