method

alias_attribute_method_definition

Importance_0
v7.1.3.2 - Show latest stable - 0 notes - Class: ActiveRecord::AttributeMethods::ClassMethods
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2 (0)
  • 7.1.3.4 (0)
  • What's this?
alias_attribute_method_definition(code_generator, pattern, new_name, old_name) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/attribute_methods.rb, line 85
      def alias_attribute_method_definition(code_generator, pattern, new_name, old_name)
        method_name = pattern.method_name(new_name).to_s
        target_name = pattern.method_name(old_name).to_s
        parameters = pattern.parameters
        old_name = old_name.to_s

        method_defined = method_defined?(target_name) || private_method_defined?(target_name)
        manually_defined = method_defined &&
          !self.instance_method(target_name).owner.is_a?(GeneratedAttributeMethods)
        reserved_method_name = ::ActiveRecord::AttributeMethods.dangerous_attribute_methods.include?(target_name)

        if !abstract_class? && !has_attribute?(old_name)
          # We only need to issue this deprecation warning once, so we issue it when defining the original reader method.
          should_warn = target_name == old_name
          if should_warn
            ActiveRecord.deprecator.warn(
              "#{self} model aliases `#{old_name}`, but `#{old_name}` is not an attribute. "                "Starting in Rails 7.2, alias_attribute with non-attribute targets will raise. "                "Use `alias_method :#{new_name}, :#{old_name}` or define the method manually."
            )
          end
          super
        elsif manually_defined && !reserved_method_name
          aliased_method_redefined_as_well = method_defined_within?(method_name, self)
          return if aliased_method_redefined_as_well

          ActiveRecord.deprecator.warn(
            "#{self} model aliases `#{old_name}` and has a method called `#{target_name}` defined. "              "Starting in Rails 7.2 `#{method_name}` will not be calling `#{target_name}` anymore. "              "You may want to additionally define `#{method_name}` to preserve the current behavior."
          )
          super
        else
          define_proxy_call(code_generator, method_name, pattern.proxy_target, parameters, old_name,
            namespace: :proxy_alias_attribute
          )
        end
      end
Register or log in to add new notes.