1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Move middleware builder back to Rails::Rack::Metal without losing the new behavior.

This commit is contained in:
José Valim 2010-01-17 13:23:14 +01:00
parent 27d9836ad3
commit 020e656447
4 changed files with 30 additions and 31 deletions

View file

@ -8,35 +8,6 @@ module ActionDispatch
require "action_dispatch/railties/subscriber"
subscriber ActionDispatch::Railties::Subscriber.new
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_dispatch.initialize_metal" do |app|
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
middleware = MetalMiddlewareBuilder.new(metals)
app.config.middleware.insert_before(:"ActionDispatch::ParamsParser", middleware)
end
# Prepare dispatcher callbacks and run 'prepare' callbacks
initializer "action_dispatch.prepare_dispatcher" do |app|
# TODO: This used to say unless defined?(Dispatcher). Find out why and fix.

View file

@ -19,6 +19,7 @@ module Rails
middleware.use('ActionDispatch::Cookies')
middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
middleware.use('ActionDispatch::Flash', :if => lambda { ActionController::Base.session_store })
middleware.use(lambda { Rails::Rack::Metal.new(Rails.application.config.paths.app.metals.to_a, Rails.application.config.metals) })
middleware.use('ActionDispatch::ParamsParser')
middleware.use('::Rack::MethodOverride')
middleware.use('::ActionDispatch::Head')

View file

@ -1,7 +1,8 @@
module Rails
module Rack
autoload :Debugger, "rails/rack/debugger"
autoload :Debugger, "rails/rack/debugger"
autoload :LogTailer, "rails/rack/log_tailer"
autoload :Static, "rails/rack/static"
autoload :Metal, "rails/rack/metal"
autoload :Static, "rails/rack/static"
end
end

View file

@ -0,0 +1,26 @@
require 'action_dispatch'
module Rails
module Rack
class Metal
def initialize(metal_roots, metals=nil)
load_list = metals || Dir["{#{metal_roots.join(",")}}/**/*.rb"]
@metals = load_list.map { |metal|
metal = File.basename(metal, '.rb')
require_dependency metal
metal.camelize.constantize
}.compact
end
def new(app)
ActionDispatch::Cascade.new(@metals, app)
end
def name
ActionDispatch::Cascade.name
end
alias_method :to_s, :name
end
end
end