Class: PGTrunk::Serializers::QualifiedNameSerializer

Inherits:
ActiveRecord::Type::Value
  • Object
show all
Defined in:
lib/pg_trunk/core/serializers/qualified_name_serializer.rb

Overview

Cast the attribute value as a qualified name.

Constant Summary collapse

TYPE =
::PGTrunk::QualifiedName

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/pg_trunk/core/serializers/qualified_name_serializer.rb', line 10

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

#serialize(value) ⇒ Object



18
19
20
# File 'lib/pg_trunk/core/serializers/qualified_name_serializer.rb', line 18

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