Module: Serega::SeregaPlugins::ActiverecordPreloads
- Defined in:
- lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb,
lib/serega/plugins/activerecord_preloads/lib/preloader.rb
Overview
Plugin :activerecord_preloads (depends on :preloads plugin, that must be loaded first)
Automatically preloads associations to serialized objects
It takes all defined preloads from serialized attributes (including attributes from serialized relations), merges them into single associations hash and then uses ActiveRecord::Associations::Preloader to preload all associations.
Defined Under Namespace
Modules: InstanceMethods Classes: ActiverecordArray, ActiverecordEnumerator, ActiverecordObject, ActiverecordRelation, Loader, Preloader
Class Method Summary collapse
-
.before_load_plugin(serializer_class, **_opts) ⇒ void
Checks requirements to load plugin.
-
.load_plugin(serializer_class, **_opts) ⇒ void
Applies plugin code to specific serializer.
-
.plugin_name ⇒ Symbol
Plugin name.
Class Method Details
.before_load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Checks requirements to load plugin
61 62 63 64 65 66 67 68 69 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 61 def self.before_load_plugin(serializer_class, **_opts) unless serializer_class.plugin_used?(:preloads) raise SeregaError, "Please load `plugin :preloads` first" end if serializer_class.plugin_used?(:batch) raise SeregaError, "Plugin `activerecord_preloads` must be loaded before `batch`" end end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
79 80 81 82 83 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 79 def self.load_plugin(serializer_class, **_opts) require_relative "./lib/preloader" serializer_class.include(InstanceMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
50 51 52 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 50 def self.plugin_name :activerecord_preloads end |