From edb8131535c74ac215bf36c0d58d2019ed091a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 26 Jan 2010 15:27:40 +0100 Subject: Move Rails::Rack::Metal to Rails::Application::Metal and just add cascade if any metal was declared. --- railties/lib/rails/application/metal.rb | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 railties/lib/rails/application/metal.rb (limited to 'railties/lib/rails/application') diff --git a/railties/lib/rails/application/metal.rb b/railties/lib/rails/application/metal.rb new file mode 100644 index 0000000000..17786dd4ba --- /dev/null +++ b/railties/lib/rails/application/metal.rb @@ -0,0 +1,46 @@ +require 'action_dispatch' + +module Rails + class Application + class Metal + def self.paths + @paths ||= [] + end + + def self.metals + @metals ||= [] + 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 = metals.map { |m| m.to_s.camelize.constantize } + self.class.metals.concat(@metals) + end + + def new(app) + ActionDispatch::Cascade.new(@metals, app) + end + + def name + ActionDispatch::Cascade.name + end + alias_method :to_s, :name + end + end +end -- cgit v1.2.3