Permalink
Browse files

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
  • Loading branch information...
1 parent 5af2be2 commit d8b173607da94419e841c4d36f251987c9acf156 @rafaelfranca rafaelfranca committed Sep 21, 2013
Showing with 10 additions and 2 deletions.
  1. +10 −2 activerecord/lib/active_record/core.rb
@@ -167,7 +167,7 @@ def relation #:nodoc:
# ==== 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? }
@@ -180,7 +180,9 @@ def initialize(attributes = nil)
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?
@@ -451,5 +453,11 @@ def init_changed_attributes
@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

0 comments on commit d8b1736

Please sign in to comment.