aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-22 15:47:46 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-22 15:47:46 -0300
commit3b814ed2b52305797451149dbb629b601a18165f (patch)
tree5bbcf2fab4697ad63d90ab65a3a7efa19b1a31dd /activerecord/lib
parent35c160066aea1f0ded952da0f3f9e78b61c38507 (diff)
parent55400052186c3b3cb15c86f38ee266e5dafed696 (diff)
downloadrails-3b814ed2b52305797451149dbb629b601a18165f.tar.gz
rails-3b814ed2b52305797451149dbb629b601a18165f.tar.bz2
rails-3b814ed2b52305797451149dbb629b601a18165f.zip
Merge pull request #15239 from croaky/dc-sg-move-extract-precision-to-types
Move `extract_precision` onto type objects
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb6
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/column.rb13
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/date_time.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/numeric.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/value.rb3
7 files changed, 15 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index a718756b93..522fa57822 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -69,15 +69,11 @@ module ActiveRecord
end
private
- delegate :extract_scale, to: :cast_type
+ delegate :extract_scale, :extract_precision, to: :cast_type
def extract_limit(sql_type)
$1.to_i if sql_type =~ /\((.*)\)/
end
-
- def extract_precision(sql_type)
- $2.to_i if sql_type =~ /^(numeric|decimal|number)\((\d+)(,\d+)?\)/i
- end
end
end
# :startdoc:
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
index 80c79642f3..302eb8a114 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
@@ -35,8 +35,6 @@ module ActiveRecord
require 'active_record/connection_adapters/postgresql/array_parser'
include PostgreSQL::ArrayParser
end
-
- attr_accessor :money_precision
end
# :startdoc:
@@ -121,17 +119,6 @@ module ActiveRecord
else super
end
end
-
- # Extracts the precision from PostgreSQL-specific data types.
- def extract_precision(sql_type)
- if sql_type == 'money'
- self.class.money_precision
- elsif sql_type =~ /timestamp/i
- $1.to_i if sql_type =~ /\((\d+)\)/
- else
- super
- end
- end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
index 1e34c09c88..74e8f30457 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb
@@ -5,6 +5,8 @@ module ActiveRecord
class Money < Type::Decimal
include Infinity
+ class_attribute :precision
+
def extract_scale(sql_type)
2
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 7d1fa0dd08..b0cbccb7ba 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -713,7 +713,7 @@ module ActiveRecord
# Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
# PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
# should know about this but can't detect it there, so deal with it here.
- PostgreSQLColumn.money_precision = (postgresql_version >= 80300) ? 19 : 10
+ OID::Money.precision = (postgresql_version >= 80300) ? 19 : 10
configure_connection
rescue ::PG::Error => error
diff --git a/activerecord/lib/active_record/connection_adapters/type/date_time.rb b/activerecord/lib/active_record/connection_adapters/type/date_time.rb
index c34f4c5a53..43203a4cd4 100644
--- a/activerecord/lib/active_record/connection_adapters/type/date_time.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/date_time.rb
@@ -8,6 +8,10 @@ module ActiveRecord
:datetime
end
+ def extract_precision(sql_type)
+ $1.to_i if sql_type =~ /\((\d+)\)/
+ end
+
private
def cast_value(string)
diff --git a/activerecord/lib/active_record/connection_adapters/type/numeric.rb b/activerecord/lib/active_record/connection_adapters/type/numeric.rb
index a3379831cb..15081daf8d 100644
--- a/activerecord/lib/active_record/connection_adapters/type/numeric.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/numeric.rb
@@ -14,6 +14,10 @@ module ActiveRecord
else super
end
end
+
+ def extract_precision(sql_type)
+ $1.to_i if sql_type =~ /\((\d+)(,\d+)?\)/
+ end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/type/value.rb b/activerecord/lib/active_record/connection_adapters/type/value.rb
index 52d9ed9bc0..6687c9a2a4 100644
--- a/activerecord/lib/active_record/connection_adapters/type/value.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/value.rb
@@ -3,8 +3,11 @@ module ActiveRecord
module Type
class Value # :nodoc:
def type; end
+
def extract_scale(sql_type); end
+ def extract_precision(sql_type); end
+
def type_cast(value)
cast_value(value) unless value.nil?
end