aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/rack/metal.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/rack/metal.rb')
-rw-r--r--railties/lib/rails/rack/metal.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb
index 565f95d7c4..732936da32 100644
--- a/railties/lib/rails/rack/metal.rb
+++ b/railties/lib/rails/rack/metal.rb
@@ -3,14 +3,29 @@ require 'action_dispatch'
module Rails
module Rack
class Metal
- def initialize(metal_roots, metals=nil)
- load_list = metals || Dir["{#{metal_roots.join(",")}}/**/*.rb"]
+ def self.paths
+ @paths ||= []
+ end
+
+ def initialize(list=nil)
+ metals = []
+ list = Array(list || :all).map(&:to_sym)
+
+ self.class.paths.each do |path|
+ matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
+ Dir.glob("#{path}/**/*.rb").sort.each do |metal_path|
+ metal = metal_path.sub(matcher, '\1').to_sym
+ next unless list.include?(metal) || list.include?(:all)
+ require_dependency metal
+ metals << metal
+ end
+ end
+
+ metals = metals.sort_by do |m|
+ [list.index(m) || list.index(:all), m.to_s]
+ end
- @metals = load_list.map { |metal|
- metal = File.basename(metal, '.rb')
- require_dependency metal
- metal.camelize.constantize
- }.compact
+ @metals = metals.map { |m| m.to_s.camelize.constantize }
end
def new(app)