Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kdmny/resque-delay
Browse files Browse the repository at this point in the history
Conflicts:
	lib/resque_delay/message_sending.rb
	lib/resque_delay/performable_method.rb
	resque-delay.gemspec
  • Loading branch information
gabriprat committed Jul 4, 2015
2 parents ee523be + 455c4bc commit 61baaac
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/resque_delay/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ module ResqueDelay
class PerformableMethod < Struct.new(:object, :method, :args, :queue, :run_in)
CLASS_STRING_FORMAT = /^CLASS\:([A-Z][\w\:]+)$/
AR_STRING_FORMAT = /^AR\:([A-Z][\w\:]+)\:(\d+)$/

DM_STRING_FORMAT = /^DM\:((?:[A-Z][a-zA-z]+)(?:\:\:[A-Z][a-zA-z]+)*)\:([\d\:]+)$/

MG_STRING_FORMAT = /^MG\:([A-Z][\w\:]+)\:(\w+)$/

def self.create(object, method, args, queue, run_in)
raise NoMethodError, "undefined method `#{method}' for #{object.inspect}" unless object.respond_to?(method, true)
self.new(object, method, args, queue, run_in)
Expand All @@ -16,12 +19,17 @@ def initialize(object, method, args, queue, run_in)
self.queue = queue
self.run_in = run_in
end

def resque_args
[object, method, args]
end

def display_name
case self.object
when CLASS_STRING_FORMAT then "#{$1}.#{method}"
when AR_STRING_FORMAT then "#{$1}##{method}"
when DM_STRING_FORMAT then "#{$1}##{method}"
when MG_STRING_FORMAT then "#{$1}##{method}"
else "Unknown##{method}"
end
end
Expand All @@ -38,11 +46,12 @@ def perform

private

def load(arg)
def load(arg)
case arg
when CLASS_STRING_FORMAT then $1.constantize
when AR_STRING_FORMAT then $1.constantize.find($2)
when DM_STRING_FORMAT then $1.constantize.get!(*$2.split(':'))
when MG_STRING_FORMAT then $1.constantize.find($2)
else arg
end
end
Expand All @@ -54,10 +63,16 @@ def dump(arg)
ar_to_string(arg)
elsif defined?(DataMapper) && arg.kind_of?(DataMapper::Resource)
dm_to_string(arg)
elsif defined?(Mongoid) && arg.is_a?(Mongoid::Document)
mg_to_string(arg)
else
arg
end
end

def mg_to_string(obj)
"MG:#{obj.class}:#{obj.id}"
end

def ar_to_string(obj)
"AR:#{obj.class}:#{obj.id}"
Expand Down

0 comments on commit 61baaac

Please sign in to comment.