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

Merge pull request #23395 from PareshGupta/remove-unused-constant

Remove unused ReaderMethodCache and  WriterMethodCache  constants from ActiveRecord
This commit is contained in:
Santiago Pastorino 2016-02-10 20:29:48 -03:00
commit 2db347bebc
3 changed files with 5 additions and 54 deletions

View file

@ -34,30 +34,6 @@ module ActiveRecord
BLACKLISTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)
class AttributeMethodCache
def initialize
@module = Module.new
@method_cache = Concurrent::Map.new
end
def [](name)
@method_cache.compute_if_absent(name) do
safe_name = name.unpack('h*'.freeze).first
temp_method = "__temp__#{safe_name}"
ActiveRecord::AttributeMethods::AttrNames.set_name_cache safe_name, name
@module.module_eval method_body(temp_method, safe_name), __FILE__, __LINE__
@module.instance_method temp_method
end
end
private
# Override this method in the subclasses for method body.
def method_body(method_name, const_name)
raise NotImplementedError, "Subclasses must implement a method_body(method_name, const_name) method."
end
end
class GeneratedAttributeMethods < Module; end # :nodoc:
module ClassMethods

View file

@ -1,8 +1,11 @@
module ActiveRecord
module AttributeMethods
module Read
ReaderMethodCache = Class.new(AttributeMethodCache) {
private
extend ActiveSupport::Concern
module ClassMethods
protected
# We want to generate the methods via module_eval rather than
# define_method, because define_method is slower on dispatch.
# Evaluating many similar methods may use more memory as the instruction
@ -21,21 +24,6 @@ module ActiveRecord
# to allocate an object on each call to the attribute method.
# Making it frozen means that it doesn't get duped when used to
# key the @attributes in read_attribute.
def method_body(method_name, const_name)
<<-EOMETHOD
def #{method_name}
name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{const_name}
_read_attribute(name) { |n| missing_attribute(n, caller) }
end
EOMETHOD
end
}.new
extend ActiveSupport::Concern
module ClassMethods
protected
def define_method_attribute(name)
safe_name = name.unpack('h*'.freeze).first
temp_method = "__temp__#{safe_name}"

View file

@ -1,19 +1,6 @@
module ActiveRecord
module AttributeMethods
module Write
WriterMethodCache = Class.new(AttributeMethodCache) {
private
def method_body(method_name, const_name)
<<-EOMETHOD
def #{method_name}(value)
name = ::ActiveRecord::AttributeMethods::AttrNames::ATTR_#{const_name}
write_attribute(name, value)
end
EOMETHOD
end
}.new
extend ActiveSupport::Concern
included do