Module: Serega::SeregaPlugins::Batch
- Defined in:
- lib/serega/plugins/batch/batch.rb,
lib/serega/plugins/batch/lib/loader.rb,
lib/serega/plugins/batch/lib/loaders.rb,
lib/serega/plugins/batch/lib/plugins_extensions.rb,
lib/serega/plugins/batch/lib/validations/check_opt_batch.rb,
lib/serega/plugins/batch/lib/validations/check_batch_opt_key.rb,
lib/serega/plugins/batch/lib/validations/check_batch_opt_loader.rb
Overview
Plugin that can be used to load attributes values in batches.
Each batch loader accepts list of selected keys, context and current attribute point.
Each batch loader must return Hash with values grouped by provided keys.
There are specific `:default` option that can be used to add default value for missing key.
Defined Under Namespace
Modules: AttributeInstanceMethods, CheckAttributeParamsInstanceMethods, ClassMethods, ConfigInstanceMethods, InstanceMethods, MapPointInstanceMethods, PluginsExtensions, SeregaObjectSerializerInstanceMethods Classes: BatchLoadersConfig, BatchModel, CheckBatchOptKey, CheckBatchOptLoader, CheckOptBatch, SeregaBatchLoader, SeregaBatchLoaders
Class Method Summary collapse
-
.after_load_plugin(serializer_class, **opts) ⇒ void
Runs callbacks after plugin was attached.
-
.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.
Runs callbacks after plugin was attached
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/serega/plugins/batch/batch.rb', line 74 def self.after_load_plugin(serializer_class, **opts) config = serializer_class.config config.attribute_keys << :batch config.opts[:batch] = {loaders: {}} serializer_class::SeregaConfig.include(ConfigInstanceMethods) batch_loaders_class = Class.new(SeregaBatchLoaders) batch_loaders_class.serializer_class = serializer_class serializer_class.const_set(:SeregaBatchLoaders, batch_loaders_class) batch_loader_class = Class.new(SeregaBatchLoader) batch_loader_class.serializer_class = serializer_class serializer_class.const_set(:SeregaBatchLoader, batch_loader_class) if serializer_class.plugin_used?(:activerecord_preloads) require_relative "./lib/plugins_extensions" serializer_class::SeregaBatchLoader.include(PluginsExtensions::ActiveRecordPreloads::BatchLoaderInstanceMethods) end if serializer_class.plugin_used?(:formatters) require_relative "./lib/plugins_extensions" serializer_class::SeregaBatchLoader.include(PluginsExtensions::Formatters::BatchLoaderInstanceMethods) end end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/serega/plugins/batch/batch.rb', line 51 def self.load_plugin(serializer_class, **_opts) require_relative "./lib/loader" require_relative "./lib/loaders" require_relative "./lib/validations/check_batch_opt_key" require_relative "./lib/validations/check_batch_opt_loader" require_relative "./lib/validations/check_opt_batch" serializer_class.extend(ClassMethods) serializer_class.include(InstanceMethods) serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods) serializer_class::SeregaAttribute.include(AttributeInstanceMethods) serializer_class::SeregaMapPoint.include(MapPointInstanceMethods) serializer_class::SeregaObjectSerializer.include(SeregaObjectSerializerInstanceMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
39 40 41 |
# File 'lib/serega/plugins/batch/batch.rb', line 39 def self.plugin_name :batch end |