123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::Normalization

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Classes:
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: activerecord/lib/active_record/normalization.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Method Summary

DSL Calls

included

[ GitHub ]


7
8
9
10
11
# File 'activerecord/lib/active_record/normalization.rb', line 7

included do
  class_attribute :normalized_attributes, default: Set.new

  before_validation :normalize_changed_in_place_attributes
end

Instance Method Details

#normalize_attribute(name)

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
[ GitHub ]

  
# File 'activerecord/lib/active_record/normalization.rb', line 26

def normalize_attribute(name)
  # Treat the value as a new, unnormalized value.
  self[name] = self[name]
end

#normalize_changed_in_place_attributes (private)

[ GitHub ]

  
# File 'activerecord/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