mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 09:13:05 +08:00
27 lines
543 B
Ruby
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
|