From 1a92f4fb6574100fb9d16cf3f8e395c3a58938d6 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 21 May 2014 09:51:36 +0200 Subject: 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 --- activerecord/lib/active_record/connection_adapters/column.rb | 2 +- .../lib/active_record/connection_adapters/postgresql/column.rb | 6 ------ .../lib/active_record/connection_adapters/postgresql/oid.rb | 4 ++++ activerecord/lib/active_record/connection_adapters/type/value.rb | 4 ++++ 4 files changed, 9 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record') 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 -- cgit v1.2.3