Module: Serega::SeregaPlugins::If
- Defined in:
- lib/serega/plugins/if/if.rb,
lib/serega/plugins/if/validations/check_opt_if.rb,
lib/serega/plugins/if/validations/check_opt_unless.rb,
lib/serega/plugins/if/validations/check_opt_if_value.rb,
lib/serega/plugins/if/validations/check_opt_unless_value.rb
Overview
Plugin :if
Adds :if, :unless, :if_value, :unless_value attribute options to
conditionally remove attributes from the response.
:if/:unless receive the serialized object and context, and are
checked before the attribute value is found. :if_value/:unless_value
receive the already-found value and context, checked after. The latter
two cannot be used with the :serializer option, since a relationship
has no "serialized value" of its own — use :if/:unless instead.
See also the plugin-free :hide option (README.md#selecting-fields),
which hides an attribute unconditionally.
Defined Under Namespace
Modules: AttributeInstanceMethods, AttributeNormalizerInstanceMethods, CheckAttributeParamsInstanceMethods, DataBuilderClassMethods, ObjectSerializerInstanceMethods, PlanPointInstanceMethods Classes: CheckOptIf, CheckOptIfValue, CheckOptUnless, CheckOptUnlessValue, KeywordConditionResolver
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
70 71 72 |
# File 'lib/serega/plugins/if/if.rb', line 70 def self.after_load_plugin(serializer_class, **opts) serializer_class.config.attribute_keys << :if << :if_value << :unless << :unless_value end |
.load_plugin(serializer_class, **_opts) ⇒ void
This method returns an undefined value.
Applies plugin code to specific serializer
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/serega/plugins/if/if.rb', line 47 def self.load_plugin(serializer_class, **_opts) require_relative "validations/check_opt_if" require_relative "validations/check_opt_if_value" require_relative "validations/check_opt_unless" require_relative "validations/check_opt_unless_value" serializer_class::SeregaAttribute.include(AttributeInstanceMethods) serializer_class::SeregaAttributeNormalizer.include(AttributeNormalizerInstanceMethods) serializer_class::SeregaPlanPoint.include(PlanPointInstanceMethods) serializer_class::CheckAttributeParams.include(CheckAttributeParamsInstanceMethods) serializer_class::SeregaObjectSerializer.include(ObjectSerializerInstanceMethods) serializer_class::SeregaDataBuilder.extend(DataBuilderClassMethods) end |
.plugin_name ⇒ Symbol
Returns Plugin name.
34 35 36 |
# File 'lib/serega/plugins/if/if.rb', line 34 def self.plugin_name :if end |