mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-15 13:45:25 +08:00
28 lines
543 B
Ruby
28 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
|