Class: ActiveSupport::FileUpdateChecker
- Defined in:
- lib/active_support/file_update_checker.rb
Overview
This class is responsible to track files and invoke the given block whenever one of these files are changed. For example, this class is used by Rails to reload the I18n framework whenever they are changed upon a new request.
i18n_reloader = ActiveSupport::FileUpdateChecker.new(paths) do
I18n.reload!
end
ActionDispatch::Reloader.to_prepare do
i18n_reloader.execute_if_updated
end
Instance Attribute Summary collapse
-
#last_update_at ⇒ Object
readonly
Returns the value of attribute last_update_at.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #execute_if_updated ⇒ Object
-
#initialize(paths, calculate = false, &block) ⇒ FileUpdateChecker
constructor
A new instance of FileUpdateChecker.
- #updated_at ⇒ Object
Constructor Details
#initialize(paths, calculate = false, &block) ⇒ FileUpdateChecker
Returns a new instance of FileUpdateChecker.
18 19 20 21 22 |
# File 'lib/active_support/file_update_checker.rb', line 18 def initialize(paths, calculate=false, &block) @paths = paths @block = block @last_update_at = calculate ? updated_at : nil end |
Instance Attribute Details
#last_update_at ⇒ Object (readonly)
Returns the value of attribute last_update_at.
16 17 18 |
# File 'lib/active_support/file_update_checker.rb', line 16 def last_update_at @last_update_at end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
16 17 18 |
# File 'lib/active_support/file_update_checker.rb', line 16 def paths @paths end |
Instance Method Details
#execute_if_updated ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/active_support/file_update_checker.rb', line 28 def execute_if_updated current_update_at = self.updated_at if @last_update_at != current_update_at @last_update_at = current_update_at @block.call end end |