Sha256: e8359f9711f32c56d7036aee95e287e939c1554ef337006dd48be17f524549f4

Contents?: true

Size: 814 Bytes

Versions: 3

Compression:

Stored size: 814 Bytes

Contents

module Delayed
  class PerformableMethod
    def initialize(object, method_name, args)
      raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

      self.object       = ShallowMongoid.dump(object)
      self.args         = args.map{|a| ShallowMongoid.dump(a) }
      self.method_name  = method_name.to_sym
    end
    
    def perform
      ShallowMongoid.load(object).send(method_name, *args.map{|a| ShallowMongoid.load(a) })
    rescue Mongoid::Errors::DocumentNotFound
      true  # do nothing if document has been removed
    end
    
    def display_name
      if object.is_a?(ShallowMongoid::DocumentStub)
        "#{object.description}##{method_name}"
      else
        "#{object.class}##{method_name}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
delayed_job_shallow_mongoid-0.3.0 lib/delayed/shallow_mongoid/performable_method.rb
delayed_job_shallow_mongoid-0.2.8 lib/delayed/performable_method.rb
delayed_job_shallow_mongoid-0.2.7 lib/delayed/performable_method.rb