aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-05-21 09:51:36 +0200
committerYves Senn <yves.senn@gmail.com>2014-05-21 09:51:36 +0200
commit1a92f4fb6574100fb9d16cf3f8e395c3a58938d6 (patch)
treea270d7c75f6fad7cc56275f2fc91591c4bf5cb19
parent6b4f6d00642d16079e5bafe487fd27ee3ff1d1fb (diff)
downloadrails-1a92f4fb6574100fb9d16cf3f8e395c3a58938d6.tar.gz
rails-1a92f4fb6574100fb9d16cf3f8e395c3a58938d6.tar.bz2
rails-1a92f4fb6574100fb9d16cf3f8e395c3a58938d6.zip
push `extract_scale` to the `Type`.
- `extract_precision`, `extract_limit`, and `extract_default` probably need to follow. - would be good to remove the delegation `Column#extract_scale`. /cc @sgrif
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/column.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/value.rb4
4 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index a23d2bd4ef..a718756b93 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -69,7 +69,7 @@ module ActiveRecord
end
private
- delegate :extract_scale, to: Type
+ delegate :extract_scale, to: :cast_type
def extract_limit(sql_type)
$1.to_i if sql_type =~ /\((.*)\)/
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
index 151ebd9adb..95f52312a5 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
@@ -123,12 +123,6 @@ module ActiveRecord
end
end
- # Extracts the scale from PostgreSQL-specific data types.
- def extract_scale(sql_type)
- # Money type has a fixed scale of 2.
- sql_type =~ /^money/ ? 2 : super
- end
-
# Extracts the precision from PostgreSQL-specific data types.
def extract_precision(sql_type)
if sql_type == 'money'
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index a951fa1522..1d0384c3df 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -39,6 +39,10 @@ module ActiveRecord
class Money < Type::Decimal
include Infinity
+ def extract_scale(sql_type)
+ 2
+ end
+
def cast_value(value)
return value unless ::String === value
diff --git a/activerecord/lib/active_record/connection_adapters/type/value.rb b/activerecord/lib/active_record/connection_adapters/type/value.rb
index 577e464553..289c27f6d4 100644
--- a/activerecord/lib/active_record/connection_adapters/type/value.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/value.rb
@@ -4,6 +4,10 @@ module ActiveRecord
class Value # :nodoc:
def type; end
+ def extract_scale(sql_type)
+ Type.extract_scale(sql_type)
+ end
+
def type_cast(value)
cast_value(value) unless value.nil?
end