Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
return early from typecasting if the value is nil
  • Loading branch information
tenderlove committed Feb 7, 2012
1 parent 9454076 commit 20440fd
Showing 1 changed file with 15 additions and 1 deletion.
Expand Up @@ -25,6 +25,8 @@ def type_cast(value)

class Money
def type_cast(value)
return if value.nil?

# Because money output is formatted according to the locale, there are two
# cases to consider (note the decimal separators):
# (1) $12,345,678.12
Expand Down Expand Up @@ -62,18 +64,24 @@ def type_cast(value)

class Integer
def type_cast(value)
value.to_i
return if value.nil?

value.to_i rescue value ? 1 : 0
end
end

class Boolean
def type_cast(value)
return if value.nil?

ConnectionAdapters::Column.value_to_boolean value
end
end

class Timestamp
def type_cast(value)
return if value.nil?

# FIXME: probably we can improve this since we know it is PG
# specific
ConnectionAdapters::Column.string_to_time value
Expand All @@ -82,6 +90,8 @@ def type_cast(value)

class Date
def type_cast(value)
return if value.nil?

# FIXME: probably we can improve this since we know it is PG
# specific
ConnectionAdapters::Column.value_to_date value
Expand All @@ -90,6 +100,8 @@ def type_cast(value)

class Time
def type_cast(value)
return if value.nil?

# FIXME: probably we can improve this since we know it is PG
# specific
ConnectionAdapters::Column.string_to_dummy_time value
Expand All @@ -98,6 +110,8 @@ def type_cast(value)

class Float
def type_cast(value)
return if value.nil?

value.to_f
end
end
Expand Down

0 comments on commit 20440fd

Please sign in to comment.