Sha256: ea142ccb272fc0f948838966cef87686c3150e1a6793128e29e8024fdef48fda
Contents?: true
Size: 1.19 KB
Versions: 14
Compression:
Stored size: 1.19 KB
Contents
module SoberSwag module Serializer ## # Provides metadata on a serializer. # All actions delegate to the base. class Meta < Base def initialize(base, meta) @base = base @metadata = meta @identifier = @base.identifier end attr_reader :base, :metadata def serialize(args, opts = {}) base.serialize(args, opts) end def meta(hash) self.class.new(base, metadata.merge(hash)) end def lazy_type @lazy_type ||= @base.lazy_type.meta(**metadata) end def type @type ||= @base.type.meta(**metadata) end 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 def lazy_type? @base.lazy_type? end end end end
Version data entries
14 entries across 14 versions & 1 rubygems