Class: SoberSwag::Serializer::Mapped

Inherits:
Base
  • Object
show all
Defined in:
lib/sober_swag/serializer/mapped.rb

Overview

A new serializer by mapping over the serialization function

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#array, #identifier, #meta, #optional, #serializer, #via_map

Constructor Details

#initialize(base, map_f) ⇒ Mapped

Create a new mapped serializer.

Parameters:

  • base (SoberSwag::Serializer::Base)

    a serializer to use after mapping

  • map_f (Proc, Lambda)

    a mapping function to use before serialization



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

#baseSoberSwag::Serializer::Base (readonly)

Returns serializer to use after mapping.

Returns:



17
18
19
# File 'lib/sober_swag/serializer/mapped.rb', line 17

def base
  @base
end

#map_fProc, ... (readonly)

Returns function to use before serialization.

Returns:

  • (Proc, Lambda, #call)

    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_typeObject



30
31
32
# File 'lib/sober_swag/serializer/mapped.rb', line 30

def lazy_type
  @base.lazy_type
end

#lazy_type?Boolean

Returns:

  • (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, options = {})
  @base.serialize(@map_f.call(object), options)
end

#typeObject



38
39
40
# File 'lib/sober_swag/serializer/mapped.rb', line 38

def type
  @base.type
end