Class: ActionView::CacheExpiry::ViewReloader
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actionview/lib/action_view/cache_expiry.rb |
Class Method Summary
- .new(watcher:, &block) ⇒ ViewReloader constructor
Instance Attribute Summary
- #updated? ⇒ Boolean readonly
Instance Method Summary
- #execute
- #all_view_paths private
- #build_watcher private
- #dirs_to_watch private
- #rebuild_watcher private
- #reload! private
Constructor Details
.new(watcher:, &block) ⇒ ViewReloader
# File 'actionview/lib/action_view/cache_expiry.rb', line 6
def initialize(watcher:, &block) @mutex = Mutex.new @watcher_class = watcher @watched_dirs = nil @watcher = nil @previous_change = false ActionView::PathRegistry.file_system_resolver_hooks << method(:rebuild_watcher) end
Instance Attribute Details
#updated? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'actionview/lib/action_view/cache_expiry.rb', line 16
def updated? build_watcher unless @watcher @previous_change || @watcher.updated? end
Instance Method Details
#all_view_paths (private)
[ GitHub ]# File 'actionview/lib/action_view/cache_expiry.rb', line 64
def all_view_paths ActionView::PathRegistry.all_file_system_resolvers.map(&:path) end
#build_watcher (private)
[ GitHub ]# File 'actionview/lib/action_view/cache_expiry.rb', line 37
def build_watcher @mutex.synchronize do old_watcher = @watcher if @watched_dirs != dirs_to_watch @watched_dirs = dirs_to_watch new_watcher = @watcher_class.new([], @watched_dirs) do reload! end @watcher = new_watcher # We must check the old watcher after initializing the new one to # ensure we don't miss any events @previous_change ||= old_watcher&.updated? end end end
#dirs_to_watch (private)
[ GitHub ]# File 'actionview/lib/action_view/cache_expiry.rb', line 60
def dirs_to_watch all_view_paths.uniq.sort end
#execute
[ GitHub ]# File 'actionview/lib/action_view/cache_expiry.rb', line 21
def execute return unless @watcher watcher = nil @mutex.synchronize do @previous_change = false watcher = @watcher end watcher.execute end
#rebuild_watcher (private)
[ GitHub ]# File 'actionview/lib/action_view/cache_expiry.rb', line 55
def rebuild_watcher return unless @watcher build_watcher end
#reload! (private)
[ GitHub ]# File 'actionview/lib/action_view/cache_expiry.rb', line 33
def reload! ActionView::LookupContext::DetailsKey.clear end