Class: ResqueDelayWithMongoid::PerformableMethod

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

Constant Summary collapse

CLASS_STRING_FORMAT =
/^CLASS\:([A-Z][\w\:]+)$/
AR_STRING_FORMAT =
/^AR\:([A-Z][\w\:]+)\:(\d+)$/
MG_STRING_FORMAT =
/^MG\:([A-Z][\w\:]+)\:(\w+)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method, args) ⇒ PerformableMethod

Returns a new instance of PerformableMethod.



12
13
14
15
16
# File 'lib/resque_delay_with_mongoid/performable_method.rb', line 12

def initialize(object, method, args)
  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/resque_delay_with_mongoid/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/resque_delay_with_mongoid/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/resque_delay_with_mongoid/performable_method.rb', line 2

def object
  @object
end

Class Method Details

.create(object, method, args) ⇒ Object

Raises:

  • (NoMethodError)


7
8
9
10
# File 'lib/resque_delay_with_mongoid/performable_method.rb', line 7

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

Instance Method Details

#display_nameObject



22
23
24
25
26
27
28
29
# File 'lib/resque_delay_with_mongoid/performable_method.rb', line 22

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

#performObject



31
32
33
34
35
36
# File 'lib/resque_delay_with_mongoid/performable_method.rb', line 31

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

#resque_argsObject



18
19
20
# File 'lib/resque_delay_with_mongoid/performable_method.rb', line 18

def resque_args
  [object, method, args]
end