Class: Queued::QueueingProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/queued/queueing_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, queue_name = nil) ⇒ QueueingProxy

Returns a new instance of QueueingProxy.



8
9
10
11
# File 'lib/queued/queueing_proxy.rb', line 8

def initialize(target, queue_name = nil)
  @target     = target
  @queue_name = (queue_name || @target.class.name.tableize).to_sym
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/queued/queueing_proxy.rb', line 13

def method_missing(method, *args)
  unless target.respond_to?(method)
    raise NoMethodError.new "Can't be invoked", method, *args
  end

  Resque::Job.create(queue_name,
    target.class,
    target.id,
    method.to_sym,
    *args)

  nil
end

Instance Attribute Details

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



6
7
8
# File 'lib/queued/queueing_proxy.rb', line 6

def queue_name
  @queue_name
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/queued/queueing_proxy.rb', line 6

def target
  @target
end