def write_attribute(name, value)
      access = database_field_name(name)
      if attribute_writable?(access)
        _assigning do
          validate_attribute_value(access, value)
          localized = fields[access].try(:localized?)
          attributes_before_type_cast[name.to_s] = value
          typed_value = typed_value_for(access, value)
          unless attributes[access] == typed_value || attribute_changed?(access)
            attribute_will_change!(access)
          end
          if localized
            attributes[access] ||= {}
            attributes[access].merge!(typed_value)
          else
            attributes[access] = typed_value
          end
          typed_value
        end
      end
    end
def write_attribute(name, value)
      access = database_field_name(name)
      if attribute_writable?(access)
        _assigning do
          validate_attribute_value(access, value)
          localized = fields[access].try(:localized?)
          attributes_before_type_cast[name.to_s] = value
          typed_value = typed_value_for(access, value)
          unless attributes[access] == typed_value || attribute_changed?(access)
            attribute_will_change!(access)
          end
          if localized
            attributes[access] ||= {}
            attributes[access].merge!(typed_value)
          else
            attributes[access] = typed_value
          end
          typed_value
        end
      end
    end
Write a single attribute to the document attribute hash. This will
 also fire the before and after update callbacks, and perform any
 necessary typecasting.

 @example Write the attribute.
   person.write_attribute(:title, "Mr.")

 @example Write the attribute (alternate syntax.)
   person[:title] = "Mr."

 @param [ String, Symbol ] name The name of the attribute to update.
 @param [ Object ] value The value to set for the attribute.

 @since 1.0.0