Skip to content

DXUI Research: Should we have a dedicated primitive for raising deprecations? #6853

@louis-bompart

Description

@louis-bompart

Unrelated to this PR: Should we have a dedicated primitive for raising deprecations?

Here's what Rails does: https://blog.saeloun.com/2024/11/19/rails-7-1-adds-application-deprecators-method/

# 1) Define a Custom Deprecator:

# config/initializers/deprecators.rb



Rails.application.deprecators[:user_full_name] = ActiveSupport::Deprecation.new("2.0", "user_full_name")



# Here, the custom deprecator :user_full_name is defined for deprecations related to the full_name method, specifying the Rails version (2.0) and a name for context.



# 2) Use the Deprecator in Code:



class User < ApplicationRecord

  def full_name

    Rails.application.deprecators[:user_full_name].warn("The `full_name` method will be removed in the next major release.")

  end

end

Benefits:

  • Encourages defining a target version

  • Standardizes how it's reported

  • Allows telemetry to track adoption

  • Allows silencing those warnings in production use

  • Allows deduplication of warnings to avoid spamming in the case of a repeated item

Originally posted by @lavoiesl in #6738

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions