Module: Serega::SeregaPlugins::Root
- Defined in:
- lib/serega/plugins/root/root.rb
Overview
Plugin :root
Allows to add root key to your serialized data
Accepts options:
- :root - specifies root for all responses
- :root_one - specifies root for single object serialization only
- :root_many - specifies root for multiple objects serialization only
Adds additional config options:
- config.root.one
- config.root.many
- config.root.one=
- config.root_many=
Default root is :data
.
Root also can be changed per serialization.
Also root can be removed for all responses by providing root: nil
. In this case no root will be added to response, but
you still can to add it per serialization
Defined Under Namespace
Modules: ClassMethods, ConfigInstanceMethods, InstanceMethods Classes: RootConfig
Constant Summary collapse
- ROOT_DEFAULT =
Returns Default response root key.
:data
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
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/serega/plugins/root/root.rb', line 85 def self.after_load_plugin(serializer_class, **opts) config = serializer_class.config default = opts.fetch(:root, ROOT_DEFAULT) one = opts.fetch(:root_one, default) many = opts.fetch(:root_many, default) config.opts[:root] = {} config.root = {one: one, many: many} config.serialize_keys << :root end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
71 72 73 74 75 |
# File 'lib/serega/plugins/root/root.rb', line 71 def self.load_plugin(serializer_class, **_opts) serializer_class.extend(ClassMethods) serializer_class.include(InstanceMethods) serializer_class::SeregaConfig.include(ConfigInstanceMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
59 60 61 |
# File 'lib/serega/plugins/root/root.rb', line 59 def self.plugin_name :root end |