diff options
Diffstat (limited to 'railties/lib/rails/application')
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/application/metal_loader.rb (renamed from railties/lib/rails/application/metal.rb) | 40 | ||||
-rw-r--r-- | railties/lib/rails/application/routes_reloader.rb | 13 |
3 files changed, 29 insertions, 28 deletions
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index d67420938a..c0b16a0090 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -15,9 +15,9 @@ module Rails end end - initializer :add_builtin_route do + initializer :add_builtin_route do |app| if Rails.env.development? - Rails::Application::RoutesReloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + app.routes_reloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end diff --git a/railties/lib/rails/application/metal.rb b/railties/lib/rails/application/metal_loader.rb index 17786dd4ba..c0f2e4f948 100644 --- a/railties/lib/rails/application/metal.rb +++ b/railties/lib/rails/application/metal_loader.rb @@ -2,20 +2,34 @@ require 'action_dispatch' module Rails class Application - class Metal - def self.paths - @paths ||= [] + class MetalLoader + attr_reader :paths, :metals + + def initialize + @paths, @metals = [], [] + end + + def build_middleware(list=nil) + load_metals!(list) + self end - def self.metals - @metals ||= [] + def new(app) + ActionDispatch::Cascade.new(@metals, app) + end + + def name + ActionDispatch::Cascade.name end + alias :to_s :name - def initialize(list=nil) + protected + + def load_metals!(list) metals = [] - list = Array(list || :all).map(&:to_sym) + list = Array(list || :all).map(&:to_sym) - self.class.paths.each do |path| + 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 @@ -30,17 +44,7 @@ module Rails 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 diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index fe0cfb7801..fde6211c5d 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,19 +1,16 @@ module Rails class Application - # TODO Write tests for this behavior extracted from Application class RoutesReloader - def self.paths - @paths ||= [] - end + attr_reader :paths - def initialize(config) - @config, @last_change_at = config, nil + def initialize + @paths, @last_change_at = [], nil end def changed_at routes_changed_at = nil - self.class.paths.each do |path| + paths.each do |path| config_changed_at = File.stat(path).mtime if routes_changed_at.nil? || config_changed_at > routes_changed_at @@ -29,7 +26,7 @@ module Rails routes.disable_clear_and_finalize = true routes.clear! - self.class.paths.each { |path| load(path) } + paths.each { |path| load(path) } routes.finalize! nil |