Class: ROM::SQL::TypeSerializer Private

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::ClassAttributes
Defined in:
lib/rom/sql/type_serializer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

Postgres::TypeSerializer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](db_type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/rom/sql/type_serializer.rb', line 17

def self.[](db_type)
  registry[db_type]
end

.register(db_type, builder) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/rom/sql/type_serializer.rb', line 13

def self.register(db_type, builder)
  registry[db_type] = builder
end

Instance Method Details

#call(type) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rom/sql/type_serializer.rb', line 35

def call(type)
  return type.meta[:db_type] if type.meta[:db_type]

  meta = type.meta[:read] ? {read: type.meta[:read]} : EMPTY_HASH

  self.class.mapping.fetch(type.with(meta: meta)) {
    if block_given?
      yield(type)
    end or raise "Cannot serialize #{type}"
  }
end