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.



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

def initialize
  @mapping = {}
end

Instance Method Details

#[](oid) ⇒ Object



281
282
283
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 281

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

#[]=(oid, type) ⇒ Object



277
278
279
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 277

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

#clearObject



285
286
287
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 285

def clear
  @mapping.clear
end

#fetch(ftype, fmod) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 293

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:



289
290
291
# File 'lib/active_record/connection_adapters/postgresql/oid.rb', line 289

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