Class: Delayed::PerformableMethod

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

Constant Summary collapse

CLASS_STRING_FORMAT =
/^CLASS\:([A-Z][\w\:]+)$/
DM_STRING_FORMAT =
/^DM\:([A-Z][\w\:]+)\:(.*)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, args) ⇒ PerformableMethod

Returns a new instance of PerformableMethod.

Raises:

  • (NoMethodError)


6
7
8
9
10
11
12
# File 'lib/dm-delayed-job/performable_method.rb', line 6

def initialize(object, method, args)
  raise NoMethodError, "undefined method `#{method}' for #{self.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



2
3
4
# File 'lib/dm-delayed-job/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/dm-delayed-job/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/dm-delayed-job/performable_method.rb', line 2

def object
  @object
end

Instance Method Details

#display_nameObject



14
15
16
17
18
19
20
# File 'lib/dm-delayed-job/performable_method.rb', line 14

def display_name  
  case self.object
  when CLASS_STRING_FORMAT then "#{$1}.#{method}"
  when DM_STRING_FORMAT then "#{$1}##{method}"
  else "Unknown##{method}"
  end      
end

#performObject



22
23
24
25
26
27
# File 'lib/dm-delayed-job/performable_method.rb', line 22

def perform
  load(object).send(method, *args.map{|a| load(a)})
rescue DataMapper::ObjectNotFoundError
  # We cannot do anything about objects which were deleted in the meantime
  true
end