From 5ea2b11ad7fb1e0e0580edd9d8e0e688cfffa3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 12 Jun 2012 10:36:13 +0200 Subject: Stop relying on mutable structures in the FileUpdateChecker --- .../lib/active_support/file_update_checker.rb | 19 ++++-------------- activesupport/lib/active_support/i18n_railtie.rb | 23 +++------------------- 2 files changed, 7 insertions(+), 35 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index 8860636168..48c39d9370 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -35,22 +35,11 @@ module ActiveSupport # have directories as keys and the value is an array of extensions to be # watched under that directory. # - # This method must also receive a block that will be called once a path changes. - # - # == Implementation details - # - # This particular implementation checks for added, updated, and removed - # files. Directories lookup are compiled to a glob for performance. - # Therefore, while someone can add new files to the +files+ array after - # initialization (and parts of Rails do depend on this feature), adding - # new directories after initialization is not supported. - # - # Notice that other objects that implement the FileUpdateChecker API may - # not even allow new files to be added after initialization. If this - # is the case, we recommend freezing the +files+ after initialization to - # avoid changes that won't make effect. + # This method must also receive a block that will be called once a path + # changes. The array of files and list of directories cannot be changed + # after FileUpdateChecker has been initialized. def initialize(files, dirs={}, &block) - @files = files + @files = files.freeze @glob = compile_glob(dirs) @block = block diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb index bbeb8d82c6..f67b221024 100644 --- a/activesupport/lib/active_support/i18n_railtie.rb +++ b/activesupport/lib/active_support/i18n_railtie.rb @@ -9,25 +9,6 @@ module I18n config.i18n.load_path = [] config.i18n.fallbacks = ActiveSupport::OrderedOptions.new - def self.reloader - @reloader ||= ActiveSupport::FileUpdateChecker.new(reloader_paths){ I18n.reload! } - end - - def self.reloader_paths - @reloader_paths ||= [] - end - - # Add I18n::Railtie.reloader to ActionDispatch callbacks. Since, at this - # point, no path was added to the reloader, I18n.reload! is not triggered - # on to_prepare callbacks. This will only happen on the config.after_initialize - # callback below. - initializer "i18n.callbacks" do |app| - app.reloaders << I18n::Railtie.reloader - ActionDispatch::Reloader.to_prepare do - I18n::Railtie.reloader.execute_if_updated - end - end - # Set the i18n configuration after initialization since a lot of # configuration is still usually done in application initializers. config.after_initialize do |app| @@ -63,7 +44,9 @@ module I18n init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks) - reloader_paths.concat I18n.load_path + reloader = ActiveSupport::FileUpdateChecker.new(I18n.load_path.dup){ I18n.reload! } + app.reloaders << reloader + ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated } reloader.execute @i18n_inited = true -- cgit v1.2.3