Module: Serega::SeregaPlugins::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.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 falseauto_preload_attributes_with_serializer
- default falseauto_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, CheckAttributeParamsInstanceMethods, ConfigInstanceMethods, InstanceMethods, MapPointInstanceMethods Classes: CheckOptPreload, CheckOptPreloadPath, EnumDeepFreeze, FormatUserPreloads, MainPreloadPath, 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
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/serega/plugins/preloads/preloads.rb', line 105 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 |
# File 'lib/serega/plugins/preloads/preloads.rb', line 81 def self.load_plugin(serializer_class, **_opts) serializer_class.include(InstanceMethods) serializer_class::SeregaAttribute.include(AttributeInstanceMethods) serializer_class::SeregaConfig.include(ConfigInstanceMethods) serializer_class::SeregaMapPoint.include(MapPointInstanceMethods) 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" require_relative "./validations/check_opt_preload_path" 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 |