Module: Serega::Plugins::Preloads

Defined in:
lib/serega/plugins/preloads/preloads.rb,
lib/serega/plugins/preloads/lib/enum_deep_freeze.rb,
lib/serega/plugins/preloads/lib/main_preload_path.rb,
lib/serega/plugins/preloads/lib/format_user_preloads.rb,
lib/serega/plugins/preloads/lib/preloads_constructor.rb,
lib/serega/plugins/preloads/validations/check_opt_preload_path.rb

Overview

Plugin adds `.preloads` method to find relations that must be preloaded

Defined Under Namespace

Modules: AttributeMethods, CheckAttributeParamsInstanceMethods, InstanceMethods Classes: CheckOptPreloadPath, EnumDeepFreeze, FormatUserPreloads, MainPreloadPath, PreloadsConstructor

Class Method Summary collapse

Class Method Details

.after_load_plugin(serializer_class, **opts) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/serega/plugins/preloads/preloads.rb', line 35

def self.after_load_plugin(serializer_class, **opts)
  config = serializer_class.config
  config[:attribute_keys] += [:preload, :preload_path]
  config[:preloads] = {
    auto_preload_attributes_with_serializer: opts.fetch(:auto_preload_attributes_with_serializer, false),
    auto_hide_attributes_with_preload: opts.fetch(:auto_hide_attributes_with_preload, false)
  }
end

.load_plugin(serializer_class, **_opts) ⇒ void

This method returns an undefined value.

Includes plugin modules to current serializer

Parameters:

  • serializer_class (Class)

    current serializer class

  • _opts (Hash)

    plugin opts



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/serega/plugins/preloads/preloads.rb', line 22

def self.load_plugin(serializer_class, **_opts)
  serializer_class.include(InstanceMethods)
  serializer_class::Attribute.include(AttributeMethods)

  serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods)

  require_relative "./lib/enum_deep_freeze"
  require_relative "./lib/format_user_preloads"
  require_relative "./lib/main_preload_path"
  require_relative "./lib/preloads_constructor"
  require_relative "./validations/check_opt_preload_path"
end

.plugin_nameSymbol

Returns plugin name.

Returns:

  • (Symbol)

    plugin name



10
11
12
# File 'lib/serega/plugins/preloads/preloads.rb', line 10

def self.plugin_name
  :preloads
end