Class: ActiveRecord::Materialized::ViewLoader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord/materialized/view_loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Eager-loads the view classes under Configuration#view_load_paths so their depends_on commit callbacks are installed even under Zeitwerk's lazy loading (development/test). Invoked by the Railtie on boot and on each code reload (via config.to_prepare); idempotent.

Without this, a view whose constant nothing has referenced yet is dormant — its after_*_commit hooks are never installed — so writes to its dependencies silently don't schedule maintenance until something first touches the class. In production (+config.eager_load = true+) every view already loads at boot, so this is a no-op there.

Class Method Summary collapse

Class Method Details

.load!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Load the configured view directories through Zeitwerk. A no-op outside Rails or when Configuration#view_load_paths is empty.



21
22
23
24
25
26
27
28
29
# File 'lib/activerecord/materialized/view_loader.rb', line 21

def load!
  return unless rails_application?

  autoloader = ::Rails.autoloaders.main
  ActiveRecord::Materialized.configuration.view_load_paths.each do |path|
    absolute = ::Rails.root.join(path).to_s
    eager_load_dir(autoloader, absolute) if File.directory?(absolute)
  end
end