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.rb146
1 files changed, 73 insertions, 73 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb
index 2f41e9e45b..95b3adae5f 100644
--- a/activerecord/lib/active_record/attribute.rb
+++ b/activerecord/lib/active_record/attribute.rb
@@ -130,108 +130,108 @@ module ActiveRecord
protected
- attr_reader :original_attribute
- alias_method :assigned?, :original_attribute
+ attr_reader :original_attribute
+ alias_method :assigned?, :original_attribute
- def initialize_dup(other)
- if defined?(@value) && @value.duplicable?
- @value = @value.dup
+ def initialize_dup(other)
+ if defined?(@value) && @value.duplicable?
+ @value = @value.dup
+ end
end
- end
-
- def changed_from_assignment?
- assigned? && type.changed?(original_value, value, value_before_type_cast)
- end
- def original_value_for_database
- if assigned?
- original_attribute.original_value_for_database
- else
- _original_value_for_database
+ def changed_from_assignment?
+ assigned? && type.changed?(original_value, value, value_before_type_cast)
end
- end
-
- def _original_value_for_database
- type.serialize(original_value)
- end
- class FromDatabase < Attribute # :nodoc:
- def type_cast(value)
- type.deserialize(value)
+ def original_value_for_database
+ if assigned?
+ original_attribute.original_value_for_database
+ else
+ _original_value_for_database
+ end
end
def _original_value_for_database
- value_before_type_cast
+ type.serialize(original_value)
end
- end
- class FromUser < Attribute # :nodoc:
- def type_cast(value)
- type.cast(value)
- end
+ class FromDatabase < Attribute # :nodoc:
+ def type_cast(value)
+ type.deserialize(value)
+ end
- def came_from_user?
- true
+ def _original_value_for_database
+ value_before_type_cast
+ end
end
- end
- class WithCastValue < Attribute # :nodoc:
- def type_cast(value)
- value
- end
+ class FromUser < Attribute # :nodoc:
+ def type_cast(value)
+ type.cast(value)
+ end
- def changed_in_place?
- false
+ def came_from_user?
+ true
+ end
end
- end
- class Null < Attribute # :nodoc:
- def initialize(name)
- super(name, nil, Type::Value.new)
- end
+ class WithCastValue < Attribute # :nodoc:
+ def type_cast(value)
+ value
+ end
- def type_cast(*)
- nil
+ def changed_in_place?
+ false
+ end
end
- def with_type(type)
- self.class.with_cast_value(name, nil, type)
- end
+ class Null < Attribute # :nodoc:
+ def initialize(name)
+ super(name, nil, Type::Value.new)
+ end
- def with_value_from_database(value)
- raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{name}`"
- end
- alias_method :with_value_from_user, :with_value_from_database
- end
+ def type_cast(*)
+ nil
+ end
- class Uninitialized < Attribute # :nodoc:
- UNINITIALIZED_ORIGINAL_VALUE = Object.new
+ def with_type(type)
+ self.class.with_cast_value(name, nil, type)
+ end
- def initialize(name, type)
- super(name, nil, type)
+ def with_value_from_database(value)
+ raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{name}`"
+ end
+ alias_method :with_value_from_user, :with_value_from_database
end
- def value
- if block_given?
- yield name
+ class Uninitialized < Attribute # :nodoc:
+ UNINITIALIZED_ORIGINAL_VALUE = Object.new
+
+ def initialize(name, type)
+ super(name, nil, type)
end
- end
- def original_value
- UNINITIALIZED_ORIGINAL_VALUE
- end
+ def value
+ if block_given?
+ yield name
+ end
+ end
- def value_for_database
- end
+ def original_value
+ UNINITIALIZED_ORIGINAL_VALUE
+ end
- def initialized?
- false
- end
+ def value_for_database
+ end
+
+ def initialized?
+ false
+ end
- def with_type(type)
- self.class.new(name, type)
+ def with_type(type)
+ self.class.new(name, type)
+ end
end
- end
- private_constant :FromDatabase, :FromUser, :Null, :Uninitialized, :WithCastValue
+ private_constant :FromDatabase, :FromUser, :Null, :Uninitialized, :WithCastValue
end
end