Skip to content

Commit 5ea2b11

Browse files
committed
Stop relying on mutable structures in the FileUpdateChecker
1 parent e6ea3fe commit 5ea2b11

File tree

2 files changed

+7
-35
lines changed

2 files changed

+7
-35
lines changed

activesupport/lib/active_support/file_update_checker.rb

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,11 @@ class FileUpdateChecker
3535
# have directories as keys and the value is an array of extensions to be
3636
# watched under that directory.
3737
#
38-
# This method must also receive a block that will be called once a path changes.
39-
#
40-
# == Implementation details
41-
#
42-
# This particular implementation checks for added, updated, and removed
43-
# files. Directories lookup are compiled to a glob for performance.
44-
# Therefore, while someone can add new files to the +files+ array after
45-
# initialization (and parts of Rails do depend on this feature), adding
46-
# new directories after initialization is not supported.
47-
#
48-
# Notice that other objects that implement the FileUpdateChecker API may
49-
# not even allow new files to be added after initialization. If this
50-
# is the case, we recommend freezing the +files+ after initialization to
51-
# avoid changes that won't make effect.
38+
# This method must also receive a block that will be called once a path
39+
# changes. The array of files and list of directories cannot be changed
40+
# after FileUpdateChecker has been initialized.
5241
def initialize(files, dirs={}, &block)
53-
@files = files
42+
@files = files.freeze
5443
@glob = compile_glob(dirs)
5544
@block = block
5645

activesupport/lib/active_support/i18n_railtie.rb

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,6 @@ class Railtie < Rails::Railtie
99
config.i18n.load_path = []
1010
config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
1111

12-
def self.reloader
13-
@reloader ||= ActiveSupport::FileUpdateChecker.new(reloader_paths){ I18n.reload! }
14-
end
15-
16-
def self.reloader_paths
17-
@reloader_paths ||= []
18-
end
19-
20-
# Add <tt>I18n::Railtie.reloader</tt> to ActionDispatch callbacks. Since, at this
21-
# point, no path was added to the reloader, I18n.reload! is not triggered
22-
# on to_prepare callbacks. This will only happen on the config.after_initialize
23-
# callback below.
24-
initializer "i18n.callbacks" do |app|
25-
app.reloaders << I18n::Railtie.reloader
26-
ActionDispatch::Reloader.to_prepare do
27-
I18n::Railtie.reloader.execute_if_updated
28-
end
29-
end
30-
3112
# Set the i18n configuration after initialization since a lot of
3213
# configuration is still usually done in application initializers.
3314
config.after_initialize do |app|
@@ -63,7 +44,9 @@ def self.initialize_i18n(app)
6344

6445
init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)
6546

66-
reloader_paths.concat I18n.load_path
47+
reloader = ActiveSupport::FileUpdateChecker.new(I18n.load_path.dup){ I18n.reload! }
48+
app.reloaders << reloader
49+
ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated }
6750
reloader.execute
6851

6952
@i18n_inited = true

0 commit comments

Comments
 (0)