aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-19 17:30:26 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-20 16:37:35 -0700
commitc4245c31c6b83c9d70b5ca29f6fd820b9ed7fb14 (patch)
tree06c3513f56238f501ff8356604a4467a82d43f94 /activerecord/lib/active_record
parent470c4dfe2d06a428af159f8688eb432529c61c2e (diff)
downloadrails-c4245c31c6b83c9d70b5ca29f6fd820b9ed7fb14.tar.gz
rails-c4245c31c6b83c9d70b5ca29f6fd820b9ed7fb14.tar.bz2
rails-c4245c31c6b83c9d70b5ca29f6fd820b9ed7fb14.zip
Delegate `klass` to the injected type object
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb15
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/binary.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/date.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/decimal.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/float.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/integer.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/string.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/time_value.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/type/value.rb4
9 files changed, 33 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 107b18ffd2..a23d2bd4ef 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, :text?, :number?, :binary?, :type_cast_for_write, to: :cast_type
+ delegate :type, :klass, :text?, :number?, :binary?, :type_cast_for_write, to: :cast_type
# Instantiates a new column in the table.
#
@@ -47,19 +47,6 @@ module ActiveRecord
!default.nil?
end
- # Returns the Ruby class that corresponds to the abstract data type.
- def klass
- case type
- when :integer then Fixnum
- when :float then Float
- when :decimal then BigDecimal
- when :datetime, :time then Time
- when :date then Date
- when :text, :string, :binary then String
- when :boolean then Object
- end
- end
-
# Casts value to an appropriate instance.
def type_cast(value)
if encoded?
diff --git a/activerecord/lib/active_record/connection_adapters/type/binary.rb b/activerecord/lib/active_record/connection_adapters/type/binary.rb
index e0ea226216..4b2d1a66e0 100644
--- a/activerecord/lib/active_record/connection_adapters/type/binary.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/binary.rb
@@ -9,6 +9,10 @@ module ActiveRecord
def binary?
true
end
+
+ def klass
+ ::String
+ end
end
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/type/date.rb b/activerecord/lib/active_record/connection_adapters/type/date.rb
index 599dbd320c..1e7205fd0b 100644
--- a/activerecord/lib/active_record/connection_adapters/type/date.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/date.rb
@@ -6,6 +6,10 @@ module ActiveRecord
:date
end
+ def klass
+ ::Date
+ end
+
private
def cast_value(value)
diff --git a/activerecord/lib/active_record/connection_adapters/type/decimal.rb b/activerecord/lib/active_record/connection_adapters/type/decimal.rb
index 6fb1a6c3b0..ac5af4b963 100644
--- a/activerecord/lib/active_record/connection_adapters/type/decimal.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/decimal.rb
@@ -8,6 +8,10 @@ module ActiveRecord
:decimal
end
+ def klass
+ ::BigDecimal
+ end
+
private
def cast_value(value)
diff --git a/activerecord/lib/active_record/connection_adapters/type/float.rb b/activerecord/lib/active_record/connection_adapters/type/float.rb
index 31d8e7d1d3..51cfa5d86a 100644
--- a/activerecord/lib/active_record/connection_adapters/type/float.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/float.rb
@@ -8,6 +8,10 @@ module ActiveRecord
:float
end
+ def klass
+ ::Float
+ end
+
private
def cast_value(value)
diff --git a/activerecord/lib/active_record/connection_adapters/type/integer.rb b/activerecord/lib/active_record/connection_adapters/type/integer.rb
index b41a726ef4..8f3469434c 100644
--- a/activerecord/lib/active_record/connection_adapters/type/integer.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/integer.rb
@@ -8,6 +8,10 @@ module ActiveRecord
:integer
end
+ def klass
+ ::Fixnum
+ end
+
private
def cast_value(value)
diff --git a/activerecord/lib/active_record/connection_adapters/type/string.rb b/activerecord/lib/active_record/connection_adapters/type/string.rb
index 24f9659c7b..55f0e1ee1c 100644
--- a/activerecord/lib/active_record/connection_adapters/type/string.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/string.rb
@@ -10,6 +10,10 @@ module ActiveRecord
true
end
+ def klass
+ ::String
+ end
+
private
def cast_value(value)
diff --git a/activerecord/lib/active_record/connection_adapters/type/time_value.rb b/activerecord/lib/active_record/connection_adapters/type/time_value.rb
index 654e5c7943..e9ca4adeda 100644
--- a/activerecord/lib/active_record/connection_adapters/type/time_value.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/time_value.rb
@@ -2,6 +2,10 @@ module ActiveRecord
module ConnectionAdapters
module Type
module TimeValue # :nodoc:
+ def klass
+ ::Time
+ end
+
private
def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil)
diff --git a/activerecord/lib/active_record/connection_adapters/type/value.rb b/activerecord/lib/active_record/connection_adapters/type/value.rb
index ba8f360eb9..577e464553 100644
--- a/activerecord/lib/active_record/connection_adapters/type/value.rb
+++ b/activerecord/lib/active_record/connection_adapters/type/value.rb
@@ -24,6 +24,10 @@ module ActiveRecord
false
end
+ def klass
+ ::Object
+ end
+
private
def cast_value(value)