提交 c4245c31 编写于 作者: S Sean Griffin

Delegate `klass` to the injected type object

上级 470c4dfe
......@@ -18,7 +18,7 @@ module Format
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 @@ def has_default?
!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?
......
......@@ -9,6 +9,10 @@ def type
def binary?
true
end
def klass
::String
end
end
end
end
......
......@@ -6,6 +6,10 @@ def type
:date
end
def klass
::Date
end
private
def cast_value(value)
......
......@@ -8,6 +8,10 @@ def type
:decimal
end
def klass
::BigDecimal
end
private
def cast_value(value)
......
......@@ -8,6 +8,10 @@ def type
:float
end
def klass
::Float
end
private
def cast_value(value)
......
......@@ -8,6 +8,10 @@ def type
:integer
end
def klass
::Fixnum
end
private
def cast_value(value)
......
......@@ -10,6 +10,10 @@ def text?
true
end
def klass
::String
end
private
def cast_value(value)
......
......@@ -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)
......
......@@ -24,6 +24,10 @@ def binary?
false
end
def klass
::Object
end
private
def cast_value(value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册