5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/couchrest/model/typecast.rb', line 5
def typecast_value(parent, property, value)
return nil if value.nil?
type = property.type
if value.instance_of?(type) || type == Object
if type == Time && !value.utc?
value.utc else
value
end
elsif type.respond_to?(:couchrest_typecast)
type.couchrest_typecast(parent, property, value)
elsif [String, Symbol, TrueClass, Integer, Float, BigDecimal, DateTime, Time, Date, Class].include?(type)
send('typecast_to_'+type.to_s.downcase, value)
else
property.build(value)
end
end
|