Sha256: adcd625fdc937f6e6cf04a4a1ac668cbd7c8d8a9cb7ef2cd4086da3d5ad95df1

Contents?: true

Size: 821 Bytes

Versions: 4

Compression:

Stored size: 821 Bytes

Contents

class Backgrounded::Handler::WorklingHandler
  class BackgroundedWorker < Workling::Base
    def perform(options = {})
      find_instance(options[:class], options[:id], options[:method]).send(options[:method], *options[:params])
    end

    private
    def find_instance(clazz, id, method)
      clazz = clazz.constantize
      clazz.respond_to?(method) ? clazz : clazz.find(id)
    end
  end

  def request(object, method, *args)
    instance, id = instance_identifiers(object)
    options = {
      :class => instance,
      :id => id,
      :method => method,
      :params => args
    }
    BackgroundedWorker.async_perform options
  end

  private
  def instance_identifiers(object)
    instance, id = if object.is_a?(Class) 
      [object.name, -1]
    else
      [object.class.name, object.id]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
backgrounded-0.7.3 lib/backgrounded/handler/workling_handler.rb
backgrounded-0.7.2 lib/backgrounded/handler/workling_handler.rb
backgrounded-0.7.1 lib/backgrounded/handler/workling_handler.rb
backgrounded-0.7.0 lib/backgrounded/handler/workling_handler.rb