mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Lazy allocate @forced_changes
It is almost no longer used in Active Record.
This commit is contained in:
parent
02e8e6ebd4
commit
5090a64aa3
1 changed files with 8 additions and 5 deletions
|
@ -7,9 +7,8 @@ module ActiveModel
|
||||||
class AttributeMutationTracker # :nodoc:
|
class AttributeMutationTracker # :nodoc:
|
||||||
OPTION_NOT_GIVEN = Object.new
|
OPTION_NOT_GIVEN = Object.new
|
||||||
|
|
||||||
def initialize(attributes, forced_changes = Set.new)
|
def initialize(attributes)
|
||||||
@attributes = attributes
|
@attributes = attributes
|
||||||
@forced_changes = forced_changes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def changed_attribute_names
|
def changed_attribute_names
|
||||||
|
@ -62,11 +61,15 @@ module ActiveModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def force_change(attr_name)
|
def force_change(attr_name)
|
||||||
forced_changes << attr_name
|
forced_changes[attr_name] = fetch_value(attr_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
attr_reader :attributes, :forced_changes
|
attr_reader :attributes
|
||||||
|
|
||||||
|
def forced_changes
|
||||||
|
@forced_changes ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
def attr_names
|
def attr_names
|
||||||
attributes.keys
|
attributes.keys
|
||||||
|
@ -82,7 +85,7 @@ module ActiveModel
|
||||||
end
|
end
|
||||||
|
|
||||||
class ForcedMutationTracker < AttributeMutationTracker # :nodoc:
|
class ForcedMutationTracker < AttributeMutationTracker # :nodoc:
|
||||||
def initialize(attributes, forced_changes = {})
|
def initialize(attributes)
|
||||||
super
|
super
|
||||||
@finalized_changes = nil
|
@finalized_changes = nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue