From d7455686332eb8b4b8aa40498f960da2cbb7ef89 Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Thu, 24 Sep 2020 01:58:53 +0300 Subject: [PATCH] DEV: Stop polluting `Class` with deprecated settings methods (#10736) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `self.class` here evaluates to `Class` and then we're calling `define_method` on it which means all classes will have those methods defined in them. For example: ``` ~/discourse(master*) ยป rails c Loading development environment (Rails 6.0.3.3) [1] pry(main)> Integer.methods => [:sqrt, :yaml_tag, :email_domains_blacklist=, :email_domains_whitelist=, :unicode_username_character_whitelist=, :user_website_domains_whitelist=, :whitelisted_link_domains=, :email_domains_blacklist, :email_domains_whitelist, :unicode_username_character_whitelist, ... ... ``` Fix here is to use `self.define_singleton_method`. --- app/models/site_setting.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index daef5fa3c96..89a5e923fc3 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -242,11 +242,11 @@ class SiteSetting < ActiveRecord::Base } ALLOWLIST_DEPRECATED_SITE_SETTINGS.each_pair do |old_method, new_method| - self.class.define_method(old_method) do + self.define_singleton_method(old_method) do Discourse.deprecate("#{old_method.to_s} is deprecated, use the #{new_method.to_s}.", drop_from: "2.6") send(new_method) end - self.class.define_method("#{old_method}=") do |args| + self.define_singleton_method("#{old_method}=") do |args| Discourse.deprecate("#{old_method.to_s} is deprecated, use the #{new_method.to_s}.", drop_from: "2.6") send("#{new_method}=", args) end