aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-26 14:28:18 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-26 14:28:18 -0700
commit8163a50fdc333f8cc5ea15c885f99b98b5b0fd70 (patch)
tree76348a440b6b61ca8061282f256280896c5a8ab4 /activerecord/lib/active_record/connection_adapters
parentcfd9d1d3e1e1d6bd51216d2e458337b5e904b7b0 (diff)
downloadrails-8163a50fdc333f8cc5ea15c885f99b98b5b0fd70.tar.gz
rails-8163a50fdc333f8cc5ea15c885f99b98b5b0fd70.tar.bz2
rails-8163a50fdc333f8cc5ea15c885f99b98b5b0fd70.zip
Extract types which don't require additional typecasting to a method
Database specific adapters shouldn't need to override `type_cast` to define types which are already in an acceptable state.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/quoting.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
index 768d2b6d36..f836e60988 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb
@@ -53,16 +53,15 @@ module ActiveRecord
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}"
@@ -124,6 +123,12 @@ module ActiveRecord
value.to_s(:db)
end
+
+ private
+
+ def types_which_need_no_typecasting
+ [nil, Numeric, String]
+ end
end
end
end