Class: Delayed::PerformableMethod

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

Defined Under Namespace

Classes: LoadError

Constant Summary collapse

STRING_FORMAT =
/^LOAD\;([A-Z][\w\:]+)(?:\;(\w+))?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, args) ⇒ PerformableMethod

Returns a new instance of PerformableMethod.

Raises:

  • (NoMethodError)


18
19
20
21
22
23
24
# File 'lib/delayed/performable_method.rb', line 18

def initialize(object, method, args)
  raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method)

  self.object = dump(object)
  self.args   = args.map { |a| dump(a) }
  self.method = method.to_sym
end

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



12
13
14
# File 'lib/delayed/performable_method.rb', line 12

def args
  @args
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



12
13
14
# File 'lib/delayed/performable_method.rb', line 12

def method
  @method
end

#objectObject

Returns the value of attribute object

Returns:

  • (Object)

    the current value of object



12
13
14
# File 'lib/delayed/performable_method.rb', line 12

def object
  @object
end

Instance Method Details

#display_nameObject



26
27
28
29
30
31
32
# File 'lib/delayed/performable_method.rb', line 26

def display_name
  if STRING_FORMAT === object
    "#{$1}#{$2 ? '#' : '.'}#{method}"
  else
    "#{object.class}##{method}"
  end
end

#performObject



34
35
36
37
38
39
# File 'lib/delayed/performable_method.rb', line 34

def perform
  load(object).send(method, *args.map{|a| load(a)})
rescue PerformableMethod::LoadError
  # We cannot do anything about objects that can't be loaded
  true
end