123456789_123456789_123456789_123456789_123456789_

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

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(watcher:, &block) ⇒ ViewReloader

[ GitHub ]

  
# 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

  rebuild_watcher

  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 18

def updated?
  @previous_change || @watcher.updated?
end

Instance Method Details

#all_view_paths (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/cache_expiry.rb', line 58

def all_view_paths
  ActionView::PathRegistry.all_file_system_resolvers.map(&:path)
end

#dirs_to_watch (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/cache_expiry.rb', line 54

def dirs_to_watch
  all_view_paths.uniq.sort
end

#execute

[ GitHub ]

  
# File 'actionview/lib/action_view/cache_expiry.rb', line 22

def execute
  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 36

def rebuild_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

#reload! (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/cache_expiry.rb', line 32

def reload!
  ActionView::LookupContext::DetailsKey.clear
end