This module contains the behavior for processing attributes.
Process the provided attributes casting them to their proper values if a
field exists for them on the document. This will be limited to only the
attributes provided in the suppied Hash
so that no extra nil
values get put into the document's attributes.
@example Process the attributes.
person.process_attributes(:title => "sir", :age => 40)
@param [ Hash ] attrs The attributes to set. @param [ Symbol ] role A role for scoped mass assignment. @param [ Boolean ] guard_protected_attributes False to skip mass assignment protection.
@since 2.0.0.rc.7
# File lib/mongoid/attributes/processing.rb, line 20 def process_attributes(attrs = nil, role = :default, guard_protected_attributes = true) with_mass_assignment(role, guard_protected_attributes) do attrs ||= {} if !attrs.empty? attrs = sanitize_for_mass_assignment(attrs, role) if guard_protected_attributes attrs.each_pair do |key, value| next if pending_attribute?(key, value) process_attribute(key, value) end end yield self if block_given? process_pending end end