PG::BasicTypeRegistry::

CoderMap class

An instance of this class stores the coders that should be used for a particular wire format (text or binary) and type cast direction (encoder or decoder).

Each coder object is filled with the PostgreSQL type name, OID, wire format and array coders are filled with the base elements_type.

Attributes

coders R
coders_by_name R
coders_by_oid R

Public Class Methods

new(result, coders_by_name, format, arraycoder)
# File lib/pg/basic_type_registry.rb, line 44
def initialize(result, coders_by_name, format, arraycoder)
        coder_map = {}

        arrays, nodes = result.partition { |row| row['typinput'] == 'array_in' }

        # populate the base types
        nodes.find_all { |row| coders_by_name.key?(row['typname']) }.each do |row|
                coder = coders_by_name[row['typname']].dup
                coder.oid = row['oid'].to_i
                coder.name = row['typname']
                coder.format = format
                coder_map[coder.oid] = coder.freeze
        end

        if arraycoder
                # populate array types
                arrays.each do |row|
                        elements_coder = coder_map[row['typelem'].to_i]
                        next unless elements_coder

                        coder = arraycoder.new
                        coder.oid = row['oid'].to_i
                        coder.name = row['typname']
                        coder.format = format
                        coder.elements_type = elements_coder
                        coder.needs_quotation = !DONT_QUOTE_TYPES[elements_coder.name]
                        coder_map[coder.oid] = coder.freeze
                end
        end

        @coders = coder_map.values.freeze
        @coders_by_name = @coders.inject({}){|h, t| h[t.name] = t; h }.freeze
        @coders_by_oid = @coders.inject({}){|h, t| h[t.oid] = t; h }.freeze
        freeze
end

Public Instance Methods

coder_by_name(name)
# File lib/pg/basic_type_registry.rb, line 84
def coder_by_name(name)
        @coders_by_name[name]
end
coder_by_oid(oid)
# File lib/pg/basic_type_registry.rb, line 88
def coder_by_oid(oid)
        @coders_by_oid[oid]
end