Sha256: 39cf1fdc1f0e0dc780e50b220f10c42360c0305990b44c80b6781bc6c1d302fe

Contents?: true

Size: 854 Bytes

Versions: 11

Compression:

Stored size: 854 Bytes

Contents

# frozen_string_literal: true

module PaperTrail
  module TypeSerializers
    # Provides an alternative method of serialization
    # and deserialization of PostgreSQL array columns.
    class PostgresArraySerializer
      def initialize(subtype, delimiter)
        @subtype = subtype
        @delimiter = delimiter
      end

      def serialize(array)
        array
      end

      def deserialize(array)
        case array
        # Needed for legacy data. If serialized array is a string
        # then it was serialized with Rails < 5.0.2.
        when ::String then deserialize_with_ar(array)
        else array
        end
      end

      private

      def deserialize_with_ar(array)
        ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.
          new(@subtype, @delimiter).
          deserialize(array)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
paper_trail-16.0.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-15.2.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/paper_trail-12.3.0/lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-15.1.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-15.0.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-14.0.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-13.0.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-12.3.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-12.2.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-12.1.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb
paper_trail-12.0.0 lib/paper_trail/type_serializers/postgres_array_serializer.rb