Skip to content
2 changes: 1 addition & 1 deletion lib/delayed/performable_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Delayed
class PerformableMailer < PerformableMethod
def perform
mailer = object.send(method_name, *args)
mailer = super
mailer.respond_to?(:deliver_now) ? mailer.deliver_now : mailer.deliver
end
end
Expand Down
34 changes: 29 additions & 5 deletions lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,42 @@ def display_name
end
end

def perform
object.send(method_name, *args) if object
if RUBY_VERSION >= '3.0'
def perform
if args_is_a_hash?
object.send(method_name, **args.first)
else
object.send(method_name, *args)
end if object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails if the only argument is intentionally a hash, for example sending partial request params to a job.

# rescue => e
# p e.message
# p args
# raise e
end

def args_is_a_hash?
args.size == 1 && args.first.is_a?(Hash)
end
else
def perform
object.send(method_name, *args) if object
end
end

def method(sym)
object.method(sym)
end

# rubocop:disable MethodMissing
def method_missing(symbol, *args)
object.send(symbol, *args)
end
method_def = []
location = caller_locations(1, 1).first
file, line = location.path, location.lineno
definition = RUBY_VERSION >= '3.0' ? '...' : '*args, &block'
method_def <<
"def method_missing(#{definition})" <<
" object.send(#{definition})" <<
"end"
module_eval(method_def.join(";"), file, line)
# rubocop:enable MethodMissing

def respond_to?(symbol, include_private = false)
Expand Down