From 02bbde4e78f958d5495c19d953aaec58bb8ef998 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 10 Jan 2010 23:09:10 -0600 Subject: Cleanup junk metal and revise API API Change: Returning a "X-Cascade: pass" header triggers the cascade instead of a 404 response. --- actionpack/lib/action_controller/railtie.rb | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index 6b94c32b2a..42257f9400 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -37,11 +37,33 @@ module ActionController ActionController::Base.view_paths = view_path if ActionController::Base.view_paths.blank? end + class MetalMiddlewareBuilder + def initialize(metals) + @metals = metals + end + + def new(app) + ActionDispatch::Cascade.new(@metals, app) + end + + def name + ActionDispatch::Cascade.name + end + alias_method :to_s, :name + end + initializer "action_controller.initialize_metal" do |app| - Rails::Rack::Metal.requested_metals = app.config.metals + metal_root = "#{Rails.root}/app/metal" + load_list = app.config.metals || Dir["#{metal_root}/**/*.rb"] + + metals = load_list.map { |metal| + metal = File.basename(metal.gsub("#{metal_root}/", ''), '.rb') + require_dependency metal + metal.camelize.constantize + }.compact - app.config.middleware.insert_before(:"ActionDispatch::ParamsParser", - Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) + middleware = MetalMiddlewareBuilder.new(metals) + app.config.middleware.insert_before(:"ActionDispatch::ParamsParser", middleware) end # # Prepare dispatcher callbacks and run 'prepare' callbacks -- cgit v1.2.3