module ActiveRecord::Normalization

Public Instance Methods

normalize_attribute(name) click to toggle source

Normalizes a specified attribute using its declared normalizations.

Examples

class User < ActiveRecord::Base
  normalizes :email, with: -> email { email.strip.downcase }
end

legacy_user = User.find(1)
legacy_user.email # => " CRUISE-CONTROL@EXAMPLE.COM\n"
legacy_user.normalize_attribute(:email)
legacy_user.email # => "cruise-control@example.com"
legacy_user.save
# File lib/active_record/normalization.rb, line 26
def normalize_attribute(name)
  # Treat the value as a new, unnormalized value.
  self[name] = self[name]
end

Private Instance Methods

normalize_changed_in_place_attributes() click to toggle source
# File lib/active_record/normalization.rb, line 112
def normalize_changed_in_place_attributes
  self.class.normalized_attributes.each do |name|
    normalize_attribute(name) if attribute_changed_in_place?(name)
  end
end