Sha256: a40fb4d211f33521235c4f0ca7458c7ac509726e4ebe837af72e9292aef16254
Contents?: true
Size: 896 Bytes
Versions: 1
Compression:
Stored size: 896 Bytes
Contents
# frozen_string_literal: true module Panko class ArraySerializer attr_accessor :subjects def initialize(subjects, options = {}) @subjects = subjects @each_serializer = options[:each_serializer] serializer_options = { only: options.fetch(:only, []), except: options.fetch(:except, []) } @descriptor = SerializationDescriptorBuilder.build(@each_serializer, serializer_options) @context = options.fetch(:context, nil) end def to_json serialize_to_json @subjects end def serialize(subjects) Oj.load(serialize_to_json(subjects)) end def to_a Oj.load(serialize_to_json(@subjects)) end def serialize_to_json(subjects) writer = Oj::StringWriter.new(mode: :rails) Panko::serialize_subjects(subjects.to_a, writer, @descriptor, @context) writer.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
panko_serializer-0.1.5 | lib/panko/array_serializer.rb |