Class: Magent::Async::Proxy

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

Instance Method Summary collapse

Constructor Details

#initialize(queue, target, test = false) ⇒ Proxy

Returns a new instance of Proxy.



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

def initialize(queue, target, test = false)
  @queue = queue
  @method_chain = []
  @target = target
  @test = test

  @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)


51
52
53
54
55
# File 'lib/magent/async.rb', line 51

def method_missing(m, *args, &blk)
  raise ArgumentError, "ruby blocks are not supported yet" if !blk.nil?
  @method_chain << [m, args]
  self
end

Instance Method Details

#commit!(priority = 3) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/magent/async.rb', line 38

def commit!(priority = 3)
  @channel.push(@target, @method_chain, priority)

  if @test
    target = @target
    @method_chain.each do |c|
      target = target.send(c[0], *c[1])
    end

    target
  end
end