1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #15205 from sgrif/sg-delegate-klass

Delegate `klass` to the injected type object
This commit is contained in:
Rafael Mendonça França 2014-05-20 21:17:38 -03:00
commit c72d6c91a7
9 changed files with 33 additions and 14 deletions

View file

@ -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?

View file

@ -9,6 +9,10 @@ module ActiveRecord
def binary?
true
end
def klass
::String
end
end
end
end

View file

@ -6,6 +6,10 @@ module ActiveRecord
:date
end
def klass
::Date
end
private
def cast_value(value)

View file

@ -8,6 +8,10 @@ module ActiveRecord
:decimal
end
def klass
::BigDecimal
end
private
def cast_value(value)

View file

@ -8,6 +8,10 @@ module ActiveRecord
:float
end
def klass
::Float
end
private
def cast_value(value)

View file

@ -8,6 +8,10 @@ module ActiveRecord
:integer
end
def klass
::Fixnum
end
private
def cast_value(value)

View file

@ -10,6 +10,10 @@ module ActiveRecord
true
end
def klass
::String
end
private
def cast_value(value)

View file

@ -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)

View file

@ -24,6 +24,10 @@ module ActiveRecord
false
end
def klass
::Object
end
private
def cast_value(value)