Sha256: 0f00530ee7e8f1fc27978586f423c0d7863495663d8561207e671801db4f97b0

Contents?: true

Size: 1015 Bytes

Versions: 9

Compression:

Stored size: 1015 Bytes

Contents

module SoberSwag
  module Serializer
    ##
    # A new serializer by mapping over the serialization function
    class Mapped < Base
      ##
      # Create a new mapped serializer.
      # @param base [SoberSwag::Serializer::Base] a serializer to use after mapping
      # @param map_f [Proc,Lambda] a mapping function to use before serialization
      def initialize(base, map_f)
        @base = base
        @map_f = map_f
      end

      ##
      # @return [SoberSwag::Serializer::Base] serializer to use after mapping
      attr_reader :base
      ##
      # @return [Proc, Lambda, #call] function to use before serialization
      attr_reader :map_f

      def serialize(object, options = {})
        @base.serialize(@map_f.call(object), options)
      end

      def lazy_type?
        @base.lazy_type?
      end

      def lazy_type
        @base.lazy_type
      end

      def finalize_lazy_type!
        @base.finalize_lazy_type!
      end

      def type
        @base.type
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sober_swag-0.25.2 lib/sober_swag/serializer/mapped.rb
sober_swag-0.25.1 lib/sober_swag/serializer/mapped.rb
sober_swag-0.25.0 lib/sober_swag/serializer/mapped.rb
sober_swag-0.24.1 lib/sober_swag/serializer/mapped.rb
sober_swag-0.24.0 lib/sober_swag/serializer/mapped.rb
sober_swag-0.23.0 lib/sober_swag/serializer/mapped.rb
sober_swag-0.22.0 lib/sober_swag/serializer/mapped.rb
sober_swag-0.21.0 lib/sober_swag/serializer/mapped.rb
sober_swag-0.20.0 lib/sober_swag/serializer/mapped.rb