Class: DataMapper::TypeMap

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-mapping/type_map.rb

Instance Method Summary collapse

Instance Method Details

#lookup_primitive(primitive, type_map = self) ⇒ Object

reversed lookup for primitive type to ruby type.

e.g.
     lookup_primitive('DATETIME')
     # => [DateTime, #<DataMapper::TypeMap::TypeChain:0x830b8>]


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dm-mapping/type_map.rb', line 8

def lookup_primitive primitive, type_map = self
  return nil unless type_map

  type_map.chains.find{ |type, chain|
    primitive.upcase == chain.primitive &&
    [Integer, Float, BigDecimal,
     String, TrueClass, FalseClass,
     DateTime, Date, Time,
     DM::Text, DM::Boolean].member?(type) &&
    # TINYINT size 1 shouldn't map to TrueClass
    chain.attributes[:size] != 1
  } or lookup_primitive(primitive, type_map.parent)
end