diff options
Diffstat (limited to 'activerecord/lib/active_record/type')
-rw-r--r-- | activerecord/lib/active_record/type/serialized.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/value.rb | 13 |
2 files changed, 10 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index a1205fa819..9144028576 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -9,7 +9,7 @@ module ActiveRecord super(subtype) end - def type_cast(value) + def type_cast_from_database(value) if is_default_value?(value) value else @@ -18,7 +18,7 @@ module ActiveRecord end def type_cast_from_user(value) - type_cast(type_cast_for_database(value)) + type_cast_from_database(type_cast_for_database(value)) end def type_cast_for_database(value) diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb index deacc398ef..efcdab1c0e 100644 --- a/activerecord/lib/active_record/type/value.rb +++ b/activerecord/lib/active_record/type/value.rb @@ -16,11 +16,8 @@ module ActiveRecord # must override this method. def type; end - # Takes an input from the database, or from attribute setters, - # and casts it to a type appropriate for this object. This method - # should not be overriden by subclasses. Instead, override `cast_value`. - def type_cast(value) - cast_value(value) unless value.nil? + def type_cast_from_database(value) + type_cast(value) end def type_cast_from_user(value) @@ -64,6 +61,12 @@ module ActiveRecord end private + # Takes an input from the database, or from attribute setters, + # and casts it to a type appropriate for this object. This method + # should not be overriden by subclasses. Instead, override `cast_value`. + def type_cast(value) # :api: public + cast_value(value) unless value.nil? + end # Responsible for casting values from external sources to the appropriate # type. Called by `type_cast` for all values except `nil`. |