1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add back options argument in the ActiveRecord::Base.initialize method

This will make easier to hook protected_attributes gem in our code
without making that gem fragile to change in Rails code base.

Closes #12243
This commit is contained in:
Rafael Mendonça França 2013-09-21 16:06:58 -03:00
parent a73fd2d3a2
commit f7b294fcea

View file

@ -163,7 +163,7 @@ module ActiveRecord
# ==== Example:
# # Instantiates a single new object
# User.new(first_name: 'Jamie')
def initialize(attributes = nil)
def initialize(attributes = nil, options = {})
defaults = self.class.column_defaults.dup
defaults.each { |k, v| defaults[k] = v.dup if v.duplicable? }
@ -176,7 +176,9 @@ module ActiveRecord
ensure_proper_type
populate_with_current_scope_attributes
assign_attributes(attributes) if attributes
# +options+ argument is only needed to make protected_attributes gem easier to hook.
# Remove it when we drop support to this gem.
init_attributes(attributes, options) if attributes
yield self if block_given?
run_callbacks :initialize unless _initialize_callbacks.empty?
@ -432,5 +434,11 @@ module ActiveRecord
@changed_attributes[attr] = orig_value if _field_changed?(attr, orig_value, @attributes[attr])
end
end
# This method is needed to make protected_attributes gem easier to hook.
# Remove it when we drop support to this gem.
def init_attributes(attributes, options)
assign_attributes(attributes)
end
end
end