Sha256: 7c2fc0645828c56158fe971dd1ae35eaa5a14e389cfaf39a7a6c4614101c0a95

Contents?: true

Size: 585 Bytes

Versions: 5

Compression:

Stored size: 585 Bytes

Contents

# frozen_string_literal: true

# @private
module PGTrunk::Serializers
  # @private
  # Cast the attribute value as a qualified name.
  class QualifiedNameSerializer < ActiveRecord::Type::Value
    TYPE = ::PGTrunk::QualifiedName

    def cast(value)
      case value
      when NilClass then nil
      when TYPE then value
      else TYPE.wrap(value.to_s)
      end
    end

    def serialize(value)
      value.is_a?(TYPE) ? value.lean : value&.to_s
    end
  end

  ActiveModel::Type.register(
    :pg_trunk_qualified_name,
    PGTrunk::Serializers::QualifiedNameSerializer,
  )
end

Version data entries

5 entries across 5 versions & 1 rubygems

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