Class: Porridge::SerializerForExtracted
- Inherits:
-
Serializer
- Object
- Serializer
- Porridge::SerializerForExtracted
- Defined in:
- lib/porridge/serializer_for_extracted.rb
Overview
SerializerForExtracted is a serializer that wraps another serializer and passes it an object that is extracted from the initial object using an Extractor.
Instance Attribute Summary collapse
-
#base ⇒ Serializer, #call
readonly
private
The base serializer to wrap.
-
#extractor ⇒ Extractor, #call
readonly
private
The extractor to use to extract a value from the object before passing it to the base serializer.
Instance Method Summary collapse
-
#call(object, input, options) ⇒ Object
Serializes the given input for the given object with the given options by first extracted a value from the given object, then passing that value, along with the given input and options, to the base serializer (#base).
-
#initialize(base, extractor) ⇒ SerializerForExtracted
constructor
Creates a new instance of SerializerForExtracted with the given base serializer and extractor.
Methods inherited from Serializer
Constructor Details
#initialize(base, extractor) ⇒ SerializerForExtracted
Creates a new instance of Porridge::SerializerForExtracted with the given base serializer and extractor.
13 14 15 16 17 18 19 |
# File 'lib/porridge/serializer_for_extracted.rb', line 13 def initialize(base, extractor) Serializer.ensure_valid!(base) Extractor.ensure_valid!(extractor) @base = base @extractor = extractor super() end |
Instance Attribute Details
#base ⇒ Serializer, #call (readonly, private)
The base serializer to wrap.
37 38 39 |
# File 'lib/porridge/serializer_for_extracted.rb', line 37 def base @base end |
Instance Method Details
#call(object, input, options) ⇒ Object
Serializes the given input for the given object with the given options by first extracted a value from the given object, then passing that value, along with the given input and options, to the base serializer (#base).
28 29 30 31 |
# File 'lib/porridge/serializer_for_extracted.rb', line 28 def call(object, input, ) extracted_value = extractor.call(object, ) base.call(extracted_value, input, ) end |