Merge pull request #50685 from seanpdoyle/current-attributes-instance-delegation

Simplify `CurrentAttribute.instance` delegation
This commit is contained in:
Jean Boussier 2024-01-09 23:32:25 +01:00 committed by GitHub
commit c144c4868b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 16 deletions

View File

@ -125,22 +125,7 @@ module ActiveSupport
end
end
ActiveSupport::CodeGenerator.batch(singleton_class, __FILE__, __LINE__) do |owner|
names.each do |name|
owner.define_cached_method(name, namespace: :current_attributes_delegation) do |batch|
batch <<
"def #{name}" <<
"instance.#{name}" <<
"end"
end
owner.define_cached_method("#{name}=", namespace: :current_attributes_delegation) do |batch|
batch <<
"def #{name}=(value)" <<
"instance.#{name} = value" <<
"end"
end
end
end
singleton_class.delegate(*names.flat_map { |name| [name, "#{name}="] }, to: :instance, as: self)
end
# Calls this callback before #reset is called on the instance. Used for resetting external collaborators that depend on current values.