aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/rack/metal.rb
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 /railties/lib/rails/rack/metal.rb
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.
Diffstat (limited to 'railties/lib/rails/rack/metal.rb')
-rw-r--r--railties/lib/rails/rack/metal.rb35
1 files changed, 22 insertions, 13 deletions
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