Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a data column is cast to a date object, like Date.new(2004, 12, 12)).
# File lib/active_record/attribute_methods/read.rb, line 75
75: def read_attribute(attr_name)
76: attr_name = attr_name.to_s
77: attr_name = self.class.primary_key if attr_name == 'id'
78: if !(value = @attributes[attr_name]).nil?
79: if column = column_for_attribute(attr_name)
80: if unserializable_attribute?(attr_name, column)
81: unserialize_attribute(attr_name)
82: else
83: column.type_cast(value)
84: end
85: else
86: value
87: end
88: else
89: nil
90: end
91: end
Returns true if the attribute is of a text column and marked for serialization.
# File lib/active_record/attribute_methods/read.rb, line 94
94: def unserializable_attribute?(attr_name, column)
95: column.text? && self.class.serialized_attributes[attr_name]
96: end
Returns the unserialized object of the attribute.
# File lib/active_record/attribute_methods/read.rb, line 99
99: def unserialize_attribute(attr_name)
100: unserialized_object = object_from_yaml(@attributes[attr_name])
101:
102: if unserialized_object.is_a?(self.class.serialized_attributes[attr_name]) || unserialized_object.nil?
103: @attributes.frozen? ? unserialized_object : @attributes[attr_name] = unserialized_object
104: else
105: raise SerializationTypeMismatch,
106: "#{attr_name} was supposed to be a #{self.class.serialized_attributes[attr_name]}, but was a #{unserialized_object.class.to_s}"
107: end
108: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.