Class: Magent::Async::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/magent/async.rb

Instance Method Summary collapse

Constructor Details

#initialize(queue, target, priority = 3) ⇒ Proxy

Returns a new instance of Proxy.



29
30
31
32
33
34
35
# File 'lib/magent/async.rb', line 29

def initialize(queue, target, priority = 3)
  @queue = queue
  @target = target
  @priority = priority

  @channel = Magent::AsyncChannel.new(@queue)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &blk) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
# File 'lib/magent/async.rb', line 47

def method_missing(m, *args, &blk)
  raise ArgumentError, "ruby blocks are not supported yet" if !blk.nil?

  commit!(m, args)
  self
end

Instance Method Details

#commit!(method_name, args) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/magent/async.rb', line 37

def commit!(method_name, args)
  if Magent.sync_mode
    @target.send(method_name, *args)
  else
    @channel.push(@target, [method_name, args], @priority)
  end

  @target
end