Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
josh committed Dec 19, 2008
1 parent c3f53f4 commit 12e416a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 44 deletions.
31 changes: 0 additions & 31 deletions railties/lib/rails/rack/cascade.rb

This file was deleted.

35 changes: 22 additions & 13 deletions railties/lib/rails/rack/metal.rb
@@ -1,26 +1,35 @@
require 'rails/rack/cascade' require 'active_support/ordered_hash'


module Rails module Rails
module Rack module Rack
module Metal class Metal
NotFoundResponse = [404, {}, []].freeze NotFoundResponse = [404, {}, []].freeze
NotFound = lambda { NotFoundResponse } NotFound = lambda { NotFoundResponse }


class << self def self.metals
def new(app) base = "#{Rails.root}/app/metal"
Cascade.new(builtins + [app]) 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
end


def builtins def initialize(app)
base = "#{Rails.root}/app/metal" @app = app
matcher = /\A#{Regexp.escape(base)}\/(.*)\.rb\Z/ @metals = ActiveSupport::OrderedHash.new
self.class.metals.each { |app| @metals[app] = true }
freeze
end


Dir["#{base}/**/*.rb"].sort.map do |file| def call(env)
file.sub!(matcher, '\1') @metals.keys.each do |app|
require file result = app.call(env)
file.classify.constantize return result unless result[0].to_i == 404
end
end end
@app.call(env)
end end
end end
end end
Expand Down

0 comments on commit 12e416a

Please sign in to comment.