Class: SoberSwag::Serializer::Mapped
- Defined in:
- lib/sober_swag/serializer/mapped.rb
Overview
A new serializer by mapping over the serialization function
Instance Attribute Summary collapse
-
#base ⇒ SoberSwag::Serializer::Base
readonly
Serializer to use after mapping.
-
#map_f ⇒ Proc, ...
readonly
Function to use before serialization.
Instance Method Summary collapse
- #finalize_lazy_type! ⇒ Object
-
#initialize(base, map_f) ⇒ Mapped
constructor
Create a new mapped serializer.
- #lazy_type ⇒ Object
- #lazy_type? ⇒ Boolean
- #serialize(object, options = {}) ⇒ Object
- #type ⇒ Object
Methods inherited from Base
#array, #identifier, #meta, #optional, #serializer, #via_map
Constructor Details
#initialize(base, map_f) ⇒ Mapped
Create a new mapped serializer.
10 11 12 13 |
# File 'lib/sober_swag/serializer/mapped.rb', line 10 def initialize(base, map_f) @base = base @map_f = map_f end |
Instance Attribute Details
#base ⇒ SoberSwag::Serializer::Base (readonly)
Returns serializer to use after mapping.
17 18 19 |
# File 'lib/sober_swag/serializer/mapped.rb', line 17 def base @base end |
#map_f ⇒ Proc, ... (readonly)
Returns function to use before serialization.
20 21 22 |
# File 'lib/sober_swag/serializer/mapped.rb', line 20 def map_f @map_f end |
Instance Method Details
#finalize_lazy_type! ⇒ Object
34 35 36 |
# File 'lib/sober_swag/serializer/mapped.rb', line 34 def finalize_lazy_type! @base.finalize_lazy_type! end |
#lazy_type ⇒ Object
30 31 32 |
# File 'lib/sober_swag/serializer/mapped.rb', line 30 def lazy_type @base.lazy_type end |
#lazy_type? ⇒ Boolean
26 27 28 |
# File 'lib/sober_swag/serializer/mapped.rb', line 26 def lazy_type? @base.lazy_type? end |
#serialize(object, options = {}) ⇒ Object
22 23 24 |
# File 'lib/sober_swag/serializer/mapped.rb', line 22 def serialize(object, = {}) @base.serialize(@map_f.call(object), ) end |
#type ⇒ Object
38 39 40 |
# File 'lib/sober_swag/serializer/mapped.rb', line 38 def type @base.type end |