Module: Serega::SeregaPlugins::Formatters
- Defined in:
- lib/serega/plugins/formatters/formatters.rb
Overview
Plugin :formatters
Allows to define value formatters one time and apply them on any attributes.
Config option ‘config.formatters.add()` can be used to add formatters.
Attribute option ‘:format` now can be used with name of formatter or with callable instance.
Formatters can accept up to 2 parameters (formatted object, context)
Defined Under Namespace
Modules: AttributeNormalizerInstanceMethods, CheckAttributeParamsInstanceMethods, ConfigInstanceMethods Classes: CheckFormatter, CheckOptFormat, FormattersConfig
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
86 87 88 89 90 91 |
# File 'lib/serega/plugins/formatters/formatters.rb', line 86 def self.after_load_plugin(serializer_class, **opts) config = serializer_class.config config.opts[:formatters] = {} config.formatters.add(opts[:formatters] || {}) config.attribute_keys << :format end |
.before_load_plugin(serializer_class, **opts) ⇒ void
This method returns an undefined value.
Checks requirements and loads additional plugins
58 59 60 61 62 |
# File 'lib/serega/plugins/formatters/formatters.rb', line 58 def self.before_load_plugin(serializer_class, **opts) if serializer_class.plugin_used?(:batch) raise SeregaError, "Plugin `formatters` must be loaded before `batch`" end end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
72 73 74 75 76 |
# File 'lib/serega/plugins/formatters/formatters.rb', line 72 def self.load_plugin(serializer_class, **_opts) serializer_class::SeregaConfig.include(ConfigInstanceMethods) serializer_class::SeregaAttributeNormalizer.include(AttributeNormalizerInstanceMethods) serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
47 48 49 |
# File 'lib/serega/plugins/formatters/formatters.rb', line 47 def self.plugin_name :formatters end |