scinote-web/lib/sti_preload.rb

28 lines
543 B
Ruby
Raw Normal View History

# 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