Skip to content

Commit

Permalink
Extract types which don't require additional typecasting to a method
Browse files Browse the repository at this point in the history
Database specific adapters shouldn't need to override `type_cast` to
define types which are already in an acceptable state.
  • Loading branch information
sgrif committed May 26, 2014
1 parent cfd9d1d commit 8163a50
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@ def type_cast(value, column)
end

case value
when String, ActiveSupport::Multibyte::Chars
when Symbol, ActiveSupport::Multibyte::Chars
value.to_s
when true then unquoted_true
when false then unquoted_false
when nil then nil
# BigDecimals need to be put in a non-normalized form and quoted.
when BigDecimal then value.to_s('F')
when Numeric then value
when Date, Time then quoted_date(value)
when Symbol then value.to_s
when *types_which_need_no_typecasting
value
else
to_type = column ? " to #{column.type}" : ""
raise TypeError, "can't cast #{value.class}#{to_type}"
Expand Down Expand Up @@ -124,6 +123,12 @@ def quoted_date(value)

value.to_s(:db)
end

private

def types_which_need_no_typecasting
[nil, Numeric, String]
end
end
end
end

0 comments on commit 8163a50

Please sign in to comment.