Class: ResqueDelayable::DelayedMethod
- Inherits:
-
Object
- Object
- ResqueDelayable::DelayedMethod
- Defined in:
- lib/resque-delayable/delayed_method.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #dequeue(method, *parameters) ⇒ Object
-
#initialize(klass, instance = nil, options = {}) ⇒ DelayedMethod
constructor
A new instance of DelayedMethod.
- #method_missing(method, *parameters) ⇒ Object
Constructor Details
#initialize(klass, instance = nil, options = {}) ⇒ DelayedMethod
Returns a new instance of DelayedMethod.
14 15 16 17 18 19 20 21 22 |
# File 'lib/resque-delayable/delayed_method.rb', line 14 def initialize(klass, instance = nil, = {}) unless instance.nil? || ResqueDelayable::ACTIVE_SERIALIZERS.any? {|klass| klass.serialize_match(instance) } raise "Cannot serialize instances of this type (#{instance.class}). Consider creating a serializer." end self.klass = klass self.instance = instance self. = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *parameters) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/resque-delayable/delayed_method.rb', line 28 def method_missing(method, *parameters) if instance.nil? raise NoMethodError.new("undefined method '#{method}' for #{self.klass}", method, parameters) unless klass.respond_to?(method) else raise NoMethodError.new("undefined method '#{method}' for #{self.instance}", method, parameters) unless instance.respond_to?(method) end if self.[:run_at] if ::Resque.respond_to?(:enqueue_at) ::Resque.enqueue_at(self.[:run_at], self.klass, method, ::ResqueDelayable::serialize_object(self.instance), *::ResqueDelayable::serialize_object(parameters)) else raise "Cannot use run_at, resque-scheduler not installed" end elsif self.[:run_in] if ::Resque.respond_to?(:enqueue_in) ::Resque.enqueue_in(self.[:run_in], self.klass, method, ::ResqueDelayable::serialize_object(self.instance), *::ResqueDelayable::serialize_object(parameters)) else raise "Cannot use run_in, resque-scheduler not installed" end else ::Resque.enqueue(self.klass, method, ::ResqueDelayable::serialize_object(self.instance), *::ResqueDelayable::serialize_object(parameters)) end true end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
11 12 13 |
# File 'lib/resque-delayable/delayed_method.rb', line 11 def instance @instance end |
#klass ⇒ Object
Returns the value of attribute klass.
10 11 12 |
# File 'lib/resque-delayable/delayed_method.rb', line 10 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/resque-delayable/delayed_method.rb', line 12 def @options end |
Instance Method Details
#dequeue(method, *parameters) ⇒ Object
24 25 26 |
# File 'lib/resque-delayable/delayed_method.rb', line 24 def dequeue(method, *parameters) ::Resque.dequeue(self.klass, method, ::ResqueDelayable::serialize_object(self.instance), *::ResqueDelayable::serialize_object(parameters)) end |