lib/backgrounded/handler/workling_handler.rb in backgrounded-0.7.3 vs lib/backgrounded/handler/workling_handler.rb in backgrounded-0.7.4
- old
+ new
@@ -1,15 +1,16 @@
class Backgrounded::Handler::WorklingHandler
class BackgroundedWorker < Workling::Base
+ INVALID_ID = -1
def perform(options = {})
find_instance(options[:class], options[:id], options[:method]).send(options[:method], *options[:params])
end
private
def 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
end
def request(object, method, *args)
instance, id = instance_identifiers(object)
@@ -23,10 +24,10 @@
end
private
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