Class: Porridge::SerializingExtractor
- Defined in:
- lib/porridge/serializing_extractor.rb
Overview
SerializingExtractor is an extractor that wraps another extractor and serializes for its output using a provided serializer. Note that SerializingExtractor passes the output of the base extractor as the object for the serializer, not the input.
Instance Attribute Summary collapse
-
#base ⇒ Extractor, #call
readonly
private
The base extractor.
-
#serializer ⇒ Serializer, #call
readonly
private
The serializer to use to serialize for the output of the base extractor.
Instance Method Summary collapse
-
#call(object, options) ⇒ Object
Extracts a value from the given object for the given options by: 1.
-
#initialize(base, serializer) ⇒ SerializingExtractor
constructor
Creates a new instance of SerializingExtractor with the given base extractor and serializer.
Methods inherited from Extractor
Constructor Details
#initialize(base, serializer) ⇒ SerializingExtractor
Creates a new instance of Porridge::SerializingExtractor with the given base extractor and serializer.
13 14 15 16 17 18 19 |
# File 'lib/porridge/serializing_extractor.rb', line 13 def initialize(base, serializer) Extractor.ensure_valid!(base) Serializer.ensure_valid!(serializer) @base = base @serializer = serializer super() end |
Instance Attribute Details
#base ⇒ Extractor, #call (readonly, private)
The base extractor.
36 37 38 |
# File 'lib/porridge/serializing_extractor.rb', line 36 def base @base end |
#serializer ⇒ Serializer, #call (readonly, private)
The serializer to use to serialize for the output of the base extractor.
40 41 42 |
# File 'lib/porridge/serializing_extractor.rb', line 40 def serializer @serializer end |
Instance Method Details
#call(object, options) ⇒ Object
Extracts a value from the given object for the given options by:
1. Using the base extractor ({#extractor}) to extract a value from the object with the given options; and
2. Passing that value as the object to {#serializer#call}. A blank hash is given as the input, and the
given options are passed along.
28 29 30 |
# File 'lib/porridge/serializing_extractor.rb', line 28 def call(object, ) serializer.call(base.call(object, ), {}, ) end |