Class: Delayed::PerformableMethod
- Inherits:
-
Struct
- Object
- Struct
- Delayed::PerformableMethod
- Defined in:
- lib/delayed/performable_method.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#method ⇒ Object
Returns the value of attribute method.
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #deep_de_ar_ize(arg) ⇒ Object
- #display_name ⇒ Object (also: #tag)
- #full_name ⇒ Object
-
#initialize(object, method, args = []) ⇒ PerformableMethod
constructor
A new instance of PerformableMethod.
- #perform ⇒ Object
Constructor Details
#initialize(object, method, args = []) ⇒ PerformableMethod
Returns a new instance of PerformableMethod.
3 4 5 6 7 8 9 |
# File 'lib/delayed/performable_method.rb', line 3 def initialize(object, method, args = []) raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method, true) self.object = object self.args = args self.method = method.to_sym end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args
2 3 4 |
# File 'lib/delayed/performable_method.rb', line 2 def args @args end |
#method ⇒ Object
Returns the value of attribute method
2 3 4 |
# File 'lib/delayed/performable_method.rb', line 2 def method @method end |
#object ⇒ Object
Returns the value of attribute object
2 3 4 |
# File 'lib/delayed/performable_method.rb', line 2 def object @object end |
Instance Method Details
#deep_de_ar_ize(arg) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/delayed/performable_method.rb', line 24 def deep_de_ar_ize(arg) case arg when Hash "{#{arg.map { |k, v| "#{deep_de_ar_ize(k)} => #{deep_de_ar_ize(v)}" }.join(', ')}}" when Array "[#{arg.map { |a| deep_de_ar_ize(a) }.join(', ')}]" when ActiveRecord::Base "#{arg.class}.find(#{arg.id})" else arg.inspect end end |
#display_name ⇒ Object Also known as: tag
11 12 13 14 15 16 17 |
# File 'lib/delayed/performable_method.rb', line 11 def display_name if object.is_a?(Module) "#{object}.#{method}" else "#{object.class}##{method}" end end |
#full_name ⇒ Object
37 38 39 40 |
# File 'lib/delayed/performable_method.rb', line 37 def full_name obj_name = object.is_a?(ActiveRecord::Base) ? "#{object.class}.find(#{object.id}).#{method}" : display_name "#{obj_name}(#{args.map { |a| deep_de_ar_ize(a) }.join(', ')})" end |
#perform ⇒ Object
20 21 22 |
# File 'lib/delayed/performable_method.rb', line 20 def perform object.send(method, *args) end |