From 8bdf952dace22af8e571d635969388984d7f82ca Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Thu, 18 Jan 2024 17:09:16 -0500 Subject: [PATCH] NH-66480: add back method_missing but with strict regex rule --- lib/solarwinds_apm/config.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/solarwinds_apm/config.rb b/lib/solarwinds_apm/config.rb index 80fa19cc..8e38e204 100644 --- a/lib/solarwinds_apm/config.rb +++ b/lib/solarwinds_apm/config.rb @@ -283,6 +283,27 @@ def self.[]=(key, value) end end # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity + + def self.method_missing(sym, *args) + class_var_name = "@@#{sym}" + + if sym.to_s =~ /\A(.{1,20})=\z/ + self[$1] = args.first + else + # Try part of the @@config hash first + if @@config.key?(sym) + self[sym] + + # Then try as a class variable + elsif self.class_variable_defined?(class_var_name.to_sym) + self.class_eval(class_var_name) + + # Congrats - You've won a brand new nil... + else + nil + end + end + end end end