aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/type/value.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/type/value.rb')
-rw-r--r--activerecord/lib/active_record/type/value.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/type/value.rb b/activerecord/lib/active_record/type/value.rb
index 1c41b28646..efcdab1c0e 100644
--- a/activerecord/lib/active_record/type/value.rb
+++ b/activerecord/lib/active_record/type/value.rb
@@ -16,15 +16,16 @@ 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)
+ type_cast(value)
end
def type_cast_for_database(value)
- type_cast_for_write(value)
+ value
end
def type_cast_for_schema(value)
@@ -50,10 +51,6 @@ module ActiveRecord
def klass # :nodoc:
end
- def type_cast_for_write(value) # :nodoc:
- value
- end
-
# +old_value+ will always be type-cast.
# +new_value+ will come straight from the database
# or from assignment, so it could be anything. Types
@@ -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`.