Module: Serega::SeregaPlugins::Preloads
- Defined in:
- lib/serega/plugins/preloads/preloads.rb,
lib/serega/plugins/preloads/lib/preload_paths.rb,
lib/serega/plugins/preloads/lib/modules/config.rb,
lib/serega/plugins/preloads/lib/preloads_config.rb,
lib/serega/plugins/preloads/lib/modules/attribute.rb,
lib/serega/plugins/preloads/lib/modules/plan_point.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.rb,
lib/serega/plugins/preloads/lib/modules/attribute_normalizer.rb,
lib/serega/plugins/preloads/lib/modules/check_attribute_params.rb,
lib/serega/plugins/preloads/validations/check_opt_preload_path.rb
Overview
Plugin ‘:preloads`
Allows to define ‘:preloads` to attributes and then allows to merge preloads from serialized attributes and return single associations hash.
Plugin accepts options:
-
‘auto_preload_attributes_with_delegate` - default false
-
‘auto_preload_attributes_with_serializer` - default false
-
‘auto_hide_attributes_with_preload` - default false
This options are very handy if you want to forget about finding preloads manually.
Preloads can be disabled with ‘preload: false` attribute option option. Also automatically added preloads can be overwritten with manually specified `preload: :another_value`.
Some examples, **please read comments in the code below**
Defined Under Namespace
Modules: AttributeInstanceMethods, AttributeNormalizerInstanceMethods, CheckAttributeParamsInstanceMethods, ConfigInstanceMethods, InstanceMethods, PlanPointInstanceMethods Classes: CheckOptPreload, CheckOptPreloadPath, FormatUserPreloads, PreloadPaths, PreloadsConfig, PreloadsConstructor
Class Method Summary collapse
-
.after_load_plugin(serializer_class, **opts) ⇒ void
Adds config options and runs other callbacks after plugin was loaded.
-
.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.
Adds config options and runs other callbacks after plugin was loaded
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/serega/plugins/preloads/preloads.rb', line 111 def self.after_load_plugin(serializer_class, **opts) config = serializer_class.config config.attribute_keys << :preload << :preload_path preloads_opts = DEFAULT_CONFIG.merge(opts.slice(*DEFAULT_CONFIG.keys)) config.opts[:preloads] = {} preloads_config = config.preloads preloads_config.auto_preload_attributes_with_delegate = preloads_opts[:auto_preload_attributes_with_delegate] preloads_config.auto_preload_attributes_with_serializer = preloads_opts[:auto_preload_attributes_with_serializer] preloads_config.auto_hide_attributes_with_preload = preloads_opts[:auto_hide_attributes_with_preload] end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/serega/plugins/preloads/preloads.rb', line 81 def self.load_plugin(serializer_class, **_opts) require_relative "./lib/format_user_preloads" require_relative "./lib/modules/attribute" require_relative "./lib/modules/attribute_normalizer" require_relative "./lib/modules/check_attribute_params" require_relative "./lib/modules/config" require_relative "./lib/modules/plan_point" require_relative "./lib/preload_paths" require_relative "./lib/preloads_config" require_relative "./lib/preloads_constructor" require_relative "./validations/check_opt_preload" require_relative "./validations/check_opt_preload_path" serializer_class.include(InstanceMethods) serializer_class::SeregaAttribute.include(AttributeInstanceMethods) serializer_class::SeregaAttributeNormalizer.include(AttributeNormalizerInstanceMethods) serializer_class::SeregaConfig.include(ConfigInstanceMethods) serializer_class::SeregaPlanPoint.include(PlanPointInstanceMethods) serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
69 70 71 |
# File 'lib/serega/plugins/preloads/preloads.rb', line 69 def self.plugin_name :preloads end |