Skip to content

Commit

Permalink
Cleanup junk metal and revise API
Browse files Browse the repository at this point in the history
API Change: Returning a "X-Cascade: pass" header triggers the cascade
instead of a 404 response.
  • Loading branch information
josh committed Jan 11, 2010
1 parent 3921586 commit 02bbde4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 65 deletions.
28 changes: 25 additions & 3 deletions actionpack/lib/action_controller/railtie.rb
Expand Up @@ -37,11 +37,33 @@ class Railtie < Rails::Railtie
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
Expand Down
1 change: 0 additions & 1 deletion railties/lib/rails/rack.rb
Expand Up @@ -2,7 +2,6 @@ module Rails
module Rack
autoload :Debugger, "rails/rack/debugger"
autoload :LogTailer, "rails/rack/log_tailer"
autoload :Metal, "rails/rack/metal"
autoload :Static, "rails/rack/static"
end
end
59 changes: 0 additions & 59 deletions railties/lib/rails/rack/metal.rb

This file was deleted.

4 changes: 2 additions & 2 deletions railties/test/application/metal_test.rb
Expand Up @@ -37,7 +37,7 @@ def self.call(env)
app_file 'app/metal/metal_a.rb', <<-RUBY
class MetalA
def self.call(env)
[404, { "Content-Type" => "text/html"}, ["Metal A"]]
[404, { "Content-Type" => "text/html", "X-Cascade" => "pass" }, ["Metal A"]]
end
end
RUBY
Expand All @@ -59,7 +59,7 @@ def self.call(env)
app_file 'app/metal/foo_metal.rb', <<-RUBY
class FooMetal
def self.call(env)
[404, { "Content-Type" => "text/html"}, ["Not Found"]]
[404, { "Content-Type" => "text/html", "X-Cascade" => "pass" }, ["Not Found"]]
end
end
RUBY
Expand Down
1 change: 1 addition & 0 deletions railties/test/application/middleware_test.rb
Expand Up @@ -20,6 +20,7 @@ def setup
"ActionDispatch::ShowExceptions",
"ActionDispatch::Callbacks",
"ActionDispatch::Session::CookieStore",
"ActionDispatch::Cascade",
"ActionDispatch::ParamsParser",
"Rack::MethodOverride",
"Rack::Head",
Expand Down

0 comments on commit 02bbde4

Please sign in to comment.