Adding support for defining cast_as on properties as a Class
This commit is contained in:
parent
64d68ecc1a
commit
dd3df8fb69
8 changed files with 34 additions and 25 deletions
|
@ -16,11 +16,19 @@ module CouchRest
|
|||
|
||||
def parse_type(type)
|
||||
if type.nil?
|
||||
@type = 'String'
|
||||
@type = String
|
||||
elsif type.is_a?(Array) && type.empty?
|
||||
@type = ['Object']
|
||||
@type = [Object]
|
||||
else
|
||||
@type = type.is_a?(Array) ? [type.first.to_s] : type.to_s
|
||||
base_type = type.is_a?(Array) ? type.first : type
|
||||
if base_type.is_a?(String)
|
||||
base_type = TrueClass if base_type.downcase == 'boolean'
|
||||
begin
|
||||
base_type = ::CouchRest.constantize(base_type) unless base_type.is_a?(Class)
|
||||
rescue # leave base type as is and convert in more/typecast
|
||||
end
|
||||
end
|
||||
@type = type.is_a?(Array) ? [base_type] : base_type
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ module CouchRest
|
|||
|
||||
def typecast_value(value, klass, init_method)
|
||||
return nil if value.nil?
|
||||
klass = ::CouchRest.constantize(klass) unless klass.is_a?(Class)
|
||||
if value.instance_of?(klass) || klass == Object
|
||||
value
|
||||
elsif [String, TrueClass, Integer, Float, BigDecimal, DateTime, Time, Date, Class].include?(klass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue