aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/attribute.rb')
-rw-r--r--activerecord/lib/active_record/attribute.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb
index 6d38224830..8cc1904575 100644
--- a/activerecord/lib/active_record/attribute.rb
+++ b/activerecord/lib/active_record/attribute.rb
@@ -30,10 +30,14 @@ module ActiveRecord
def value
# `defined?` is cheaper than `||=` when we get back falsy values
- @value = type_cast(value_before_type_cast) unless defined?(@value)
+ @value = original_value unless defined?(@value)
@value
end
+ def original_value
+ type_cast(value_before_type_cast)
+ end
+
def value_for_database
type.type_cast_for_database(value)
end
@@ -54,7 +58,7 @@ module ActiveRecord
self.class.from_database(name, value, type)
end
- def type_cast
+ def type_cast(*)
raise NotImplementedError
end
@@ -62,6 +66,13 @@ module ActiveRecord
true
end
+ def ==(other)
+ self.class == other.class &&
+ name == other.name &&
+ value_before_type_cast == other.value_before_type_cast &&
+ type == other.type
+ end
+
protected
def initialize_dup(other)