Class: Delayed::PerformableMethod
- Inherits:
-
Object
- Object
- Delayed::PerformableMethod
- Defined in:
- lib/delayed/performable_method.rb,
lib/delayed/psych_ext.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #display_name ⇒ Object
-
#encode_with(coder) ⇒ Object
serialize to YAML.
-
#initialize(object, method_name, args) ⇒ PerformableMethod
constructor
A new instance of PerformableMethod.
- #method_missing(symbol, *args) ⇒ Object
- #perform ⇒ Object
- #respond_to?(symbol, include_private = false) ⇒ Boolean
Constructor Details
#initialize(object, method_name, args) ⇒ PerformableMethod
Returns a new instance of PerformableMethod.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/delayed/performable_method.rb', line 9 def initialize(object, method_name, args) raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true) if defined?(ActiveRecord) && object.kind_of?(ActiveRecord::Base) raise(ArgumentError, 'Jobs cannot be created for records before they\'ve been persisted') if object.attributes[object.class.primary_key].nil? end self.object = object self.args = args self.method_name = method_name.to_sym end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
29 30 31 |
# File 'lib/delayed/performable_method.rb', line 29 def method_missing(symbol, *args) object.send(symbol, *args) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
5 6 7 |
# File 'lib/delayed/performable_method.rb', line 5 def args @args end |
#method_name ⇒ Object
Returns the value of attribute method_name.
5 6 7 |
# File 'lib/delayed/performable_method.rb', line 5 def method_name @method_name end |
#object ⇒ Object
Returns the value of attribute object.
5 6 7 |
# File 'lib/delayed/performable_method.rb', line 5 def object @object end |
Instance Method Details
#display_name ⇒ Object
21 22 23 |
# File 'lib/delayed/performable_method.rb', line 21 def display_name "#{object.class}##{method_name}" end |
#encode_with(coder) ⇒ Object
serialize to YAML
13 14 15 16 17 18 19 |
# File 'lib/delayed/psych_ext.rb', line 13 def encode_with(coder) coder.map = { "object" => object, "method_name" => method_name, "args" => args } end |
#perform ⇒ Object
25 26 27 |
# File 'lib/delayed/performable_method.rb', line 25 def perform object.send(method_name, *args) if object end |
#respond_to?(symbol, include_private = false) ⇒ Boolean
33 34 35 |
# File 'lib/delayed/performable_method.rb', line 33 def respond_to?(symbol, include_private=false) super || object.respond_to?(symbol, include_private) end |