diff options
-rw-r--r-- | railties/lib/rails/rack/cascade.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/rack/metal.rb | 35 |
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 |