Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::OID::TypeMap

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/postgresql/oid.rb

Instance Method Summary collapse

Constructor Details

#initializeTypeMap

Returns a new instance of TypeMap.



256
257
258
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 256

def initialize
  @mapping = {}
end

Instance Method Details

#[](oid) ⇒ Object



264
265
266
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 264

def [](oid)
  @mapping[oid]
end

#[]=(oid, type) ⇒ Object



260
261
262
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 260

def []=(oid, type)
  @mapping[oid] = type
end

#clearObject



268
269
270
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 268

def clear
  @mapping.clear
end

#fetch(ftype, fmod) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 276

def fetch(ftype, fmod)
  # The type for the numeric depends on the width of the field,
  # so we'll do something special here.
  #
  # When dealing with decimal columns:
  #
  # places after decimal  = fmod - 4 & 0xffff
  # places before decimal = (fmod - 4) >> 16 & 0xffff
  if ftype == 1700 && (fmod - 4 & 0xffff).zero?
    ftype = 23
  end

  @mapping.fetch(ftype) { |oid| yield oid, fmod }
end

#key?(oid) ⇒ Boolean

Returns:



272
273
274
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 272

def key?(oid)
  @mapping.key? oid
end