lib/backgrounded/handler/resque_handler.rb in backgrounded-0.7.3 vs lib/backgrounded/handler/resque_handler.rb in backgrounded-0.7.4
- old
+ new
@@ -3,14 +3,15 @@
module Backgrounded
module Handler
#enque requests in resque
class ResqueHandler
DEFAULT_QUEUE = 'backgrounded'
+ INVALID_ID = -1
@@queue = DEFAULT_QUEUE
def request(object, method, *args)
- options = object.send("#{method.to_s.sub(/([?!=])$/, '')}_backgrounded_options")
+ options = object.send Backgrounded.method_name_for_backgrounded_options(method)
@@queue = options[:queue] || DEFAULT_QUEUE
instance, id = instance_identifiers(object)
Resque.enqueue(ResqueHandler, instance, id, method, *args)
end
def self.queue
@@ -21,14 +22,14 @@
end
private
def self.find_instance(clazz, id, method)
clazz = clazz.constantize
- clazz.respond_to?(method) ? clazz : clazz.find(id)
+ id.to_i == INVALID_ID ? clazz : clazz.find(id)
end
def instance_identifiers(object)
instance, id = if object.is_a?(Class)
- [object.name, -1]
+ [object.name, INVALID_ID]
else
[object.class.name, object.id]
end
end
end