Kernel.module_eval do # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors # The cases of 'id' and '_self' both handle instances, with the difference # being that 'id' works for objects that have a database record, while '_self' # works for non database supported instanes, such as an Exporter instance. def new_job(_method, *args, **kwargs) if instance_methods(false).include? _method define_method "#{_method}_job" do |_self = nil, *args, **kwargs| Eitil::SingleMethodJob.perform_later( *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs ) end elsif singleton_methods(false).include? _method define_singleton_method "#{_method}_job" do |*args, **kwargs| Eitil::SingleMethodJob.perform_later( *args, _class: to_s, _method: _method.to_s, **kwargs ) end end end # BEWARE: This is an exact copy of the above method, except for .perform_now instead of .perform_later and the method's name. # The reason for not using helper methods is to not unnecessarily fill and potentially fuck up the Kernel environment. def new_job_debugger(_method, *args, **kwargs) if instance_methods(false).include? _method define_method "#{_method}_job_debugger" do |_self = nil, *args, **kwargs| Eitil::SingleMethodJob.perform_now( *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs ) end elsif singleton_methods(false).include? _method define_singleton_method "#{_method}_job_debugger" do |*args, **kwargs| Eitil::SingleMethodJob.perform_now( *args, _class: to_s, _method: _method.to_s, **kwargs ) end end end end