Module: Serega::SeregaPlugins::ContextMetadata
- Defined in:
- lib/serega/plugins/context_metadata/context_metadata.rb
Overview
Plugin :context_metadata
Depends on: :root
plugin, that must be loaded first
Allows to specify metadata to be added to serialized response.
Defined Under Namespace
Modules: CheckSerializeParamsInstanceMethods, ConfigInstanceMethods, InstanceMethods Classes: ContextMetadataConfig
Constant Summary collapse
- DEFAULT_CONTEXT_METADATA_KEY =
Default context metadata option name
:meta
Class Method Summary collapse
-
.after_load_plugin(serializer_class, **opts) ⇒ void
Adds config options and runs other callbacks after plugin was loaded.
-
.before_load_plugin(serializer_class, **opts) ⇒ void
Checks requirements and loads additional plugins.
-
.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
65 66 67 68 69 70 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 65 def self.after_load_plugin(serializer_class, **opts) config = serializer_class.config = opts[:context_metadata_key] || DEFAULT_CONTEXT_METADATA_KEY config.opts[:context_metadata] = {key: } config.serialize_keys << end |
.before_load_plugin(serializer_class, **opts) ⇒ void
This method returns an undefined value.
Checks requirements and loads additional plugins
37 38 39 40 41 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 37 def self.before_load_plugin(serializer_class, **opts) unless serializer_class.plugin_used?(:root) raise SeregaError, "Please load :root plugin first so we can wrap serialization response into top-level hash to add metadata there" 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 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 51 def self.load_plugin(serializer_class, **_opts) serializer_class.include(InstanceMethods) serializer_class::SeregaConfig.include(ConfigInstanceMethods) serializer_class::CheckSerializeParams.include(CheckSerializeParamsInstanceMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
26 27 28 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 26 def self.plugin_name :context_metadata end |