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
Automatically preloads associations to serialized objects
Every association declared with :preload is loaded once during serialization using
ActiveRecord::Associations::Preloader, so there are no N+1 queries.
Defined Under Namespace
Classes: ActiverecordArray, ActiverecordEnumerator, ActiverecordObject, ActiverecordRelation, Loader, Preloader
Class Method Summary collapse
-
.after_load_plugin(serializer_class, **_opts) ⇒ void
Registers the ActiveRecord preload handler.
-
.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
.after_load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Registers the ActiveRecord preload handler
84 85 86 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 84 def self.after_load_plugin(serializer_class, **_opts) serializer_class.preload_with { |objects, preloads| Preloader.preload(objects, preloads) } end |
.before_load_plugin(serializer_class, **opts) ⇒ void
This method returns an undefined value.
Checks requirements to load plugin
58 59 60 61 62 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 58 def self.before_load_plugin(serializer_class, **opts) opts.each_key do |key| raise SeregaError, "Plugin #{plugin_name.inspect} does not accept the #{key.inspect} option. No options are allowed" end end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
72 73 74 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 72 def self.load_plugin(serializer_class, **_opts) require_relative "lib/preloader" end |
.plugin_name ⇒ Symbol
Returns Plugin name.
47 48 49 |
# File 'lib/serega/plugins/activerecord_preloads/activerecord_preloads.rb', line 47 def self.plugin_name :activerecord_preloads end |