Sha256: 8676b809978613090a7a03b36213c88fce936aa8c69ff8bfc27938a14e07be13
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
class Class def load_for_delayed_job(arg) self end def dump_for_delayed_job name end end module Delayed class PerformableMethod < Struct.new(:object, :method, :args) STRING_FORMAT = /^LOAD\;([A-Z][\w\:]+)(?:\;(\w+))?$/ class LoadError < StandardError end 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 def display_name if STRING_FORMAT === object "#{$1}#{$2 ? '#' : '.'}#{method}" else "#{object.class}##{method}" end end def perform load(object).send(method, *args.map{|a| load(a)}) rescue PerformableMethod::LoadError => le # We cannot do anything about objects that can't be loaded true end private def load(obj) if STRING_FORMAT === obj $1.constantize.load_for_delayed_job($2) else obj end rescue => e Delayed::Worker.logger.warn "Could not load object for job: #{e.message}" raise PerformableMethod::LoadError end def dump(obj) if obj.respond_to?(:dump_for_delayed_job) "LOAD;#{obj.dump_for_delayed_job}" else obj end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
emipair-delayed_job-2.0.3.1 | lib/delayed/performable_method.rb |