From 810bdea24d4dfea9d799b2241d08e7af0fafbb5b Mon Sep 17 00:00:00 2001 From: Russell Smith Date: Fri, 22 Mar 2024 11:02:39 -0700 Subject: [PATCH] WIP to remove eval usage, but this is broken on things like 1.odd? --- lib/queue_classic/worker.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/queue_classic/worker.rb b/lib/queue_classic/worker.rb index 9a4b639..b294b6f 100644 --- a/lib/queue_classic/worker.rb +++ b/lib/queue_classic/worker.rb @@ -134,9 +134,16 @@ def process(queue, job) # the object and pass the args. def call(job) args = job[:args] - receiver_str, _, message = job[:method].rpartition('.') - receiver = eval(receiver_str) - receiver.send(message, *args) + method_chain = job[:method].split('.') + + # Start with the base receiver, which should be a constant 🤞 + base_receiver_str = method_chain.shift + base_receiver = base_receiver_str.split('::').inject(Object) { |acc, val| acc.const_get(val) } + + # run through the chain of methods 🚀 + method_chain.reduce(base_receiver) do |receiver, method| + method == method_chain.last ? receiver.send(method, *args) : receiver.send(method) + end end def handle_success(queue, job)