From 4d4d2c3896ed5a5d74da833c5c3132f406f4eab7 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Tue, 3 Mar 2009 12:39:19 -0600 Subject: Enhanced Rails Metal - the load order of metals can now be configured [#2057 state:resolved] Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 6 ++++++ railties/lib/rails/rack/metal.rb | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 24ce3e75ff..edea4e513a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -559,6 +559,7 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal + Rails::Rack::Metal.requested_metals = configuration.metals Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths configuration.middleware.insert_before( @@ -715,6 +716,11 @@ Run `rake gems:install` to install the missing gems. @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym } end + # The list of metals to load. If this is set to nil, all metals will + # be loaded in alphabetical order. If this is set to [], no metals will + # be loaded. Otherwise metals will be loaded in the order specified + attr_accessor :metals + # The path to the root of the plugins directory. By default, it is in # vendor/plugins. attr_accessor :plugin_paths diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index 8dac992ef2..bce59f4c78 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -8,16 +8,26 @@ module Rails cattr_accessor :metal_paths self.metal_paths = ["#{Rails.root}/app/metal"] + cattr_accessor :requested_metals def self.metals matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } + all_metals = {} Dir[*metal_glob].sort.map do |file| - path = file.match(matcher)[1] - require path - path.classify.constantize + file = file.match(matcher)[1] + all_metals[file.classify] = file end + + load_list = requested_metals || all_metals.keys + + load_list.map do |requested_metal| + if metal = all_metals[requested_metal] + require metal + requested_metal.constantize + end + end.compact end def initialize(app) -- cgit v1.2.3