aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb16
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/column.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/oid.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/binary.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/decimal.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/float.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/integer.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/numeric.rb11
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/string.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/value.rb12
-rw-r--r--activerecord/test/cases/adapters/postgresql/composite_test.rb2
12 files changed, 44 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index f46f9af239..0f0aa9110e 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -18,7 +18,7 @@ module ActiveRecord
alias :encoded? :coder
- delegate :type, to: :cast_type
+ delegate :type, :text?, :number?, :binary?, to: :cast_type
# Instantiates a new column in the table.
#
@@ -43,16 +43,6 @@ module ActiveRecord
@coder = nil
end
- # Returns +true+ if the column is either of type string or text.
- def text?
- type == :string || type == :text
- end
-
- # Returns +true+ if the column is either of type integer, float or decimal.
- def number?
- type == :integer || type == :float || type == :decimal
- end
-
def has_default?
!default.nil?
end
@@ -70,10 +60,6 @@ module ActiveRecord
end
end
- def binary?
- type == :binary
- end
-
# Casts a Ruby value to something appropriate for writing to the database.
# Numeric columns will typecast boolean and string to appropriate numeric
# values.
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
index e5118b5427..aba721eece 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb
@@ -21,14 +21,6 @@ module ActiveRecord
@default_function = default if has_default_function?(default_value, default)
end
- def number?
- !array && super
- end
-
- def text?
- !array && super
- end
-
# :stopdoc:
class << self
include PostgreSQL::Cast
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
index 94afc3aec5..56b856acf6 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
@@ -14,6 +14,10 @@ module ActiveRecord
def initialize(type)
@type = type
end
+
+ def text?
+ false
+ end
end
class Bit < Type::String
diff --git a/activerecord/lib/active_record/connection_adapters/type.rb b/activerecord/lib/active_record/connection_adapters/type.rb
index f215266560..763176cb2b 100644
--- a/activerecord/lib/active_record/connection_adapters/type.rb
+++ b/activerecord/lib/active_record/connection_adapters/type.rb
@@ -1,3 +1,4 @@
+require 'active_record/connection_adapters/type/numeric'
require 'active_record/connection_adapters/type/time_value'
require 'active_record/connection_adapters/type/value'
diff --git a/activerecord/lib/active_record/connection_adapters/type/binary.rb b/activerecord/lib/active_record/connection_adapters/type/binary.rb
index 168d824d3d..e0ea226216 100644
--- a/activerecord/lib/active_record/connection_adapters/type/binary.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/binary.rb
@@ -5,6 +5,10 @@ module ActiveRecord
def type
:binary
end
+
+ def binary?
+ true
+ end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/type/decimal.rb b/activerecord/lib/active_record/connection_adapters/type/decimal.rb
index 9581cd5964..91957fe84b 100644
--- a/activerecord/lib/active_record/connection_adapters/type/decimal.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/decimal.rb
@@ -2,6 +2,8 @@ module ActiveRecord
module ConnectionAdapters
module Type
class Decimal < Value # :nodoc:
+ include Numeric
+
def type
:decimal
end
diff --git a/activerecord/lib/active_record/connection_adapters/type/float.rb b/activerecord/lib/active_record/connection_adapters/type/float.rb
index 2d436d4aa3..31d8e7d1d3 100644
--- a/activerecord/lib/active_record/connection_adapters/type/float.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/float.rb
@@ -2,6 +2,8 @@ module ActiveRecord
module ConnectionAdapters
module Type
class Float < Value # :nodoc:
+ include Numeric
+
def type
:float
end
diff --git a/activerecord/lib/active_record/connection_adapters/type/integer.rb b/activerecord/lib/active_record/connection_adapters/type/integer.rb
index b839e043ad..fbc72ae4ef 100644
--- a/activerecord/lib/active_record/connection_adapters/type/integer.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/integer.rb
@@ -2,6 +2,8 @@ module ActiveRecord
module ConnectionAdapters
module Type
class Integer < Value # :nodoc:
+ include Numeric
+
def type
:integer
end
diff --git a/activerecord/lib/active_record/connection_adapters/type/numeric.rb b/activerecord/lib/active_record/connection_adapters/type/numeric.rb
new file mode 100644
index 0000000000..a440de4d14
--- /dev/null
+++ b/activerecord/lib/active_record/connection_adapters/type/numeric.rb
@@ -0,0 +1,11 @@
+module ActiveRecord
+ module ConnectionAdapters
+ module Type
+ module Numeric # :nodoc:
+ def number?
+ true
+ end
+ end
+ end
+ end
+end
diff --git a/activerecord/lib/active_record/connection_adapters/type/string.rb b/activerecord/lib/active_record/connection_adapters/type/string.rb
index d6c1c64834..24f9659c7b 100644
--- a/activerecord/lib/active_record/connection_adapters/type/string.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/string.rb
@@ -6,6 +6,10 @@ module ActiveRecord
:string
end
+ def text?
+ true
+ end
+
private
def cast_value(value)
diff --git a/activerecord/lib/active_record/connection_adapters/type/value.rb b/activerecord/lib/active_record/connection_adapters/type/value.rb
index a83f0e652d..506f402fef 100644
--- a/activerecord/lib/active_record/connection_adapters/type/value.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/value.rb
@@ -8,6 +8,18 @@ module ActiveRecord
cast_value(value) unless value.nil?
end
+ def text?
+ false
+ end
+
+ def number?
+ false
+ end
+
+ def binary?
+ false
+ end
+
private
def cast_value(value)
diff --git a/activerecord/test/cases/adapters/postgresql/composite_test.rb b/activerecord/test/cases/adapters/postgresql/composite_test.rb
index 1e7071c136..f01717d1a7 100644
--- a/activerecord/test/cases/adapters/postgresql/composite_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/composite_test.rb
@@ -83,7 +83,7 @@ end
class PostgresqlCompositeWithCustomOIDTest < ActiveRecord::TestCase
include PostgresqlCompositeBehavior
- class FullAddressType
+ class FullAddressType < ActiveRecord::ConnectionAdapters::Type::Value
def type; :full_address end
def type_cast(value)