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
74 75 76 77 78 79 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 74 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 42 43 44 45 46 47 48 49 50 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 37 def self.before_load_plugin(serializer_class, **opts) allowed_keys = %i[context_metadata_key] opts.each_key do |key| next if allowed_keys.include?(key) raise SeregaError, "Plugin #{plugin_name.inspect} does not accept the #{key.inspect} option. Allowed options:\n" \ " - :context_metadata_key [Symbol] - The key name that must be used to add metadata. Default is :meta." end unless serializer_class.plugin_used?(:root) raise SeregaError, "Plugin #{plugin_name.inspect} must be loaded after the :root plugin. Please load the :root plugin first" end end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
60 61 62 63 64 |
# File 'lib/serega/plugins/context_metadata/context_metadata.rb', line 60 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 |