Class: DataMapper::TypeMap
- Object
- DataMapper::TypeMap
Attributes
Instance Attributes
| chains | [RW] | public |
Sets the attribute chains. |
|---|---|---|---|
| parent | [RW] | public |
Sets the attribute parent. |
Constructor Summary
public
initialize(parent = nil, &blk)
[View source]
6 7 8 9 10
# File 'dm-core/lib/dm-core/type_map.rb', line 6 def initialize(parent = nil, &blk) @parent, @chains = parent, {} blk.call(self) unless blk.nil? end
Public Visibility
Public Instance Method Summary
| #lookup(type) | |
|---|---|
| #lookup_by_type(type) | |
| #lookup_from_map(type) | |
| #lookup_from_parent(type) | |
| #map(type) | |
| #type_mapped?(type) |
Public Instance Methods Inherited from Object
Public Instance Method Details
lookup
public
lookup(type)
[View source]
16 17 18 19 20 21 22 23 24 25
# File 'dm-core/lib/dm-core/type_map.rb', line 16 def lookup(type) if type_mapped?(type) lookup_from_map(type) else lookup_by_type(type) end end
lookup_by_type
public
lookup_by_type(type)
[View source]
37 38 39 40 41
# File 'dm-core/lib/dm-core/type_map.rb', line 37 def lookup_by_type(type) raise DataMapper::TypeMap::Error.new(type) unless type.respond_to?(:primitive) && !type.primitive.nil? lookup(type.primitive).merge(Type::PROPERTY_OPTIONS.inject({}) {|h, k| h[k] = type.send(k); h}) end
lookup_from_map
public
lookup_from_map(type)
[View source]
24 25 26
# File 'dm-core/lib/dm-core/type_map.rb', line 24 def lookup_from_map(type) lookup_from_parent(type).merge(map(type).translate) end
lookup_from_parent
public
lookup_from_parent(type)
[View source]
28 29 30 31 32 33 34 35 36 37
# File 'dm-core/lib/dm-core/type_map.rb', line 28 def lookup_from_parent(type) if !@parent.nil? && @parent.type_mapped?(type) @parent[type] else {} end end
map
public
map(type)
[View source]
12 13 14
# File 'dm-core/lib/dm-core/type_map.rb', line 12 def map(type) @chains[type] ||= TypeChain.new end
type_mapped?
public
type_mapped?(type)
[View source]
45 46 47
# File 'dm-core/lib/dm-core/type_map.rb', line 45 def type_mapped?(type) @chains.has_key?(type) || (@parent.nil? ? false : @parent.type_mapped?(type)) end