lib/active_model/attribute_methods.rb in activemodel-5.1.7 vs lib/active_model/attribute_methods.rb in activemodel-5.2.0.beta1

- old
+ new

@@ -1,7 +1,8 @@ +# frozen_string_literal: true + require "concurrent/map" -require "mutex_m" module ActiveModel # Raised when an attribute is not defined. # # class User < ActiveRecord::Base @@ -66,13 +67,12 @@ NAME_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?=]?\z/ CALL_COMPILABLE_REGEXP = /\A[a-zA-Z_]\w*[!?]?\z/ included do - class_attribute :attribute_aliases, :attribute_method_matchers, instance_writer: false - self.attribute_aliases = {} - self.attribute_method_matchers = [ClassMethods::AttributeMethodMatcher.new] + class_attribute :attribute_aliases, instance_writer: false, default: {} + class_attribute :attribute_method_matchers, instance_writer: false, default: [ ClassMethods::AttributeMethodMatcher.new ] end module ClassMethods # Declares a method available for all attributes with the given prefix. # Uses +method_missing+ and <tt>respond_to?</tt> to rewrite the method. @@ -326,17 +326,15 @@ instance_methods.each { |m| undef_method(m) } end attribute_method_matchers_cache.clear end - def generated_attribute_methods #:nodoc: - @generated_attribute_methods ||= Module.new { - extend Mutex_m - }.tap { |mod| include mod } - end - private + def generated_attribute_methods + @generated_attribute_methods ||= Module.new.tap { |mod| include mod } + end + def instance_method_already_implemented?(method_name) generated_attribute_methods.method_defined?(method_name) end # The methods +method_missing+ and +respond_to?+ of this module are @@ -469,8 +467,12 @@ matches.detect { |match| attribute_method?(match.attr_name) } end def missing_attribute(attr_name, stack) raise ActiveModel::MissingAttributeError, "missing attribute: #{attr_name}", stack + end + + def _read_attribute(attr) + __send__(attr) end end end