Sha256: 123338d564658492bfa6febea7faa41f3b2d619035f8ebbf723fa8aa3d7d0fd6

Contents?: true

Size: 648 Bytes

Versions: 5

Compression:

Stored size: 648 Bytes

Contents

# frozen_string_literal: true

# @private
module PGTrunk::Serializers
  # @private
  # The same as the array of strings with symbolization at the end
  class ArrayOfSymbolsSerializer < ActiveRecord::Type::Value
    def cast(value)
      case value
      when ::NilClass then []
      when ::Symbol then [value]
      when ::String
        value.gsub(/^\{|\}$/, "").split(",").map(&:to_sym)
      when ::Array then value.map { |i| i.to_s.to_sym }
      else [value.to_s.to_sym]
      end
    end

    def serialize(value)
      value
    end
  end

  ActiveModel::Type.register(
    :pg_trunk_array_of_symbols,
    ArrayOfSymbolsSerializer,
  )
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 lib/pg_trunk/core/serializers/array_of_symbols_serializer.rb
pg_trunk-0.1.3 lib/pg_trunk/core/serializers/array_of_symbols_serializer.rb
pg_trunk-0.1.2 lib/pg_trunk/core/serializers/array_of_symbols_serializer.rb
pg_trunk-0.1.1 lib/pg_trunk/core/serializers/array_of_symbols_serializer.rb
pg_trunk-0.1.0 lib/pg_trunk/core/serializers/array_of_symbols_serializer.rb