scinote-web/lib/sti_preload.rb
2021-08-30 10:49:14 +02:00

27 lines
543 B
Ruby

# frozen_string_literal: true
module StiPreload
unless Rails.application.config.eager_load
extend ActiveSupport::Concern
included do
cattr_accessor :preloaded, instance_accessor: false
end
class_methods do
def descendants
preload_sti unless preloaded
super
end
def preload_sti
Extends::STI_PRELOAD_CLASSES.each do |type|
logger.debug("Preloading STI type #{type}")
type.constantize
end
self.preloaded = true
end
end
end
end