Class: ResqueExtensions::AsyncMethod
- Inherits:
-
Object
- Object
- ResqueExtensions::AsyncMethod
- Defined in:
- lib/resque_extensions/async_method.rb
Constant Summary collapse
- OPTIONAL_SETTINGS =
[:queue]
- ACTIVERECORD_PREFIX =
"_ActiveRecord::"
- CLASS_PREFIX =
"_Class::"
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Class Method Summary collapse
Instance Method Summary collapse
-
#class_method? ⇒ Boolean
Is the caller a class or an instance of a class.
-
#enqueue! ⇒ Object
enqueue the job so that it can be performed.
-
#initialize(caller, method, *args) ⇒ AsyncMethod
constructor
Constructor.
-
#instance_method? ⇒ Boolean
Is the caller an instance or a class.
-
#perform ⇒ Object
Run our method.
-
#queue ⇒ Object
the queue for this job.
Constructor Details
#initialize(caller, method, *args) ⇒ AsyncMethod
Constructor
20 21 22 23 24 25 26 27 |
# File 'lib/resque_extensions/async_method.rb', line 20 def initialize(caller, method, *args) @caller = caller @method = method # set up our options self.(args) # leftover args are assigned @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
10 11 12 |
# File 'lib/resque_extensions/async_method.rb', line 10 def args @args end |
Class Method Details
.perform(*args) ⇒ Object
12 13 14 |
# File 'lib/resque_extensions/async_method.rb', line 12 def self.perform(*args) self.new(*self.reify_data(args)).perform end |
Instance Method Details
#class_method? ⇒ Boolean
Is the caller a class or an instance of a class
31 32 33 |
# File 'lib/resque_extensions/async_method.rb', line 31 def class_method? @caller.is_a?(Class) end |
#enqueue! ⇒ Object
enqueue the job so that it can be performed
37 38 39 40 41 |
# File 'lib/resque_extensions/async_method.rb', line 37 def enqueue! Resque::Job.create( self.queue, self.class, *self.data_to_enqueue ) end |
#instance_method? ⇒ Boolean
Is the caller an instance or a class
44 45 46 |
# File 'lib/resque_extensions/async_method.rb', line 44 def instance_method? !self.class_method? end |
#perform ⇒ Object
Run our method
49 50 51 |
# File 'lib/resque_extensions/async_method.rb', line 49 def perform @caller.send(@method, *@args) end |
#queue ⇒ Object
the queue for this job
54 55 56 |
# File 'lib/resque_extensions/async_method.rb', line 54 def queue @queue ||= "default" end |