Class: Delayed::PerformableMethod

Inherits:
Struct
  • Object
show all
Defined in:
lib/delayed/performable_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, args = []) ⇒ PerformableMethod

Returns a new instance of PerformableMethod.

Raises:

  • (NoMethodError)


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

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



2
3
4
# File 'lib/delayed/performable_method.rb', line 2

def args
  @args
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



2
3
4
# File 'lib/delayed/performable_method.rb', line 2

def method
  @method
end

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of 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_nameObject 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_nameObject



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

#performObject



20
21
22
# File 'lib/delayed/performable_method.rb', line 20

def perform
  object.send(method, *args)
end