Class: SoberSwag::Serializer::Meta

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

Overview

Provides metadata on a serializer. All actions delegate to the base.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(base, meta) ⇒ Meta

Returns a new instance of Meta.



7
8
9
10
11
# File 'lib/sober_swag/serializer/meta.rb', line 7

def initialize(base, meta)
  @base = base
  @metadata = meta
  @identifier = @base.identifier
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



13
14
15
# File 'lib/sober_swag/serializer/meta.rb', line 13

def base
  @base
end

#metadataObject (readonly)

Returns the value of attribute metadata.



13
14
15
# File 'lib/sober_swag/serializer/meta.rb', line 13

def 
  @metadata
end

Instance Method Details

#finalize_lazy_type!Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sober_swag/serializer/meta.rb', line 31

def finalize_lazy_type!
  @base.finalize_lazy_type!
  # Using .meta on dry-struct returns a *new type* that wraps the old one.
  # As such, we need to be a bit clever about when we tack on the identifier
  # for this type.
  %i[lazy_type type].each do |sym|
    if @base.public_send(sym).respond_to?(:identifier) && public_send(sym).respond_to?(:identifier)
      public_send(sym).identifier(@base.public_send(sym).identifier)
    end
  end
end

#lazy_typeObject



23
24
25
# File 'lib/sober_swag/serializer/meta.rb', line 23

def lazy_type
  @lazy_type ||= @base.lazy_type.meta(**)
end

#lazy_type?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sober_swag/serializer/meta.rb', line 43

def lazy_type?
  @base.lazy_type?
end

#meta(hash) ⇒ Object



19
20
21
# File 'lib/sober_swag/serializer/meta.rb', line 19

def meta(hash)
  self.class.new(base, .merge(hash))
end

#serialize(args, opts = {}) ⇒ Object



15
16
17
# File 'lib/sober_swag/serializer/meta.rb', line 15

def serialize(args, opts = {})
  base.serialize(args, opts)
end

#typeObject



27
28
29
# File 'lib/sober_swag/serializer/meta.rb', line 27

def type
  @type ||= @base.type.meta(**)
end