From 82b2bf2ba65fc206c72bd8aab223fe1441eae3f0 Mon Sep 17 00:00:00 2001 From: Shintaro Tanaka Date: Thu, 20 Apr 2023 17:56:45 +0900 Subject: [PATCH] Puts warn when Object#delay is called with block --- lib/delayed/message_sending.rb | 4 ++-- lib/delayed/performable_method.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/delayed/message_sending.rb b/lib/delayed/message_sending.rb index a2808fd39..d59432fc0 100644 --- a/lib/delayed/message_sending.rb +++ b/lib/delayed/message_sending.rb @@ -7,8 +7,8 @@ def initialize(payload_class, target, options) end # rubocop:disable MethodMissing - def method_missing(method, *args) - Job.enqueue({:payload_object => @payload_class.new(@target, method.to_sym, args)}.merge(@options)) + def method_missing(method, *args, &block) + Job.enqueue({:payload_object => @payload_class.new(@target, method.to_sym, args, &block)}.merge(@options)) end # rubocop:enable MethodMissing end diff --git a/lib/delayed/performable_method.rb b/lib/delayed/performable_method.rb index 96a28b056..44d1a16c4 100644 --- a/lib/delayed/performable_method.rb +++ b/lib/delayed/performable_method.rb @@ -2,8 +2,9 @@ module Delayed class PerformableMethod attr_accessor :object, :method_name, :args - def initialize(object, method_name, args) + def initialize(object, method_name, args, &block) raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true) + warn "Ignored the block #{block.inspect} because it cannot be serialized." if block_given? if object.respond_to?(:persisted?) && !object.persisted? raise(ArgumentError, "job cannot be created for non-persisted record: #{object.inspect}")