Class: Ass

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

Defined Under Namespace

Modules: Callback Classes: Client, Peeper, Server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_exchange) ⇒ Ass

uh… we’ll assume that the exchanges are all direct exchanges.



11
12
13
# File 'lib/ass.rb', line 11

def initialize(server_exchange)
  @server_exchange = get_exchange(server_exchange)
end

Instance Attribute Details

#server_exchangeObject (readonly)

Returns the value of attribute server_exchange.



4
5
6
# File 'lib/ass.rb', line 4

def server_exchange
  @server_exchange
end

Class Method Details

.declare(server_exchange) ⇒ Object



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

def self.declare(server_exchange)
  self.new([server_exchange,{:passive => true}])
end

Instance Method Details

#client(client_exchange, *args) ⇒ Object



15
16
17
18
19
# File 'lib/ass.rb', line 15

def client(client_exchange,*args)
  @client_exchange ||= get_exchange(client_exchange)
  q = get_queue(@client_exchange,*args) 
  Client.new(@server_exchange,@client_exchange,q)
end

#get_exchange(arg) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ass.rb', line 25

def get_exchange(arg)
  case arg
  when Array
    exchanges = exchange[0]
    opts = exchange[1]
  else
    exchange = arg
    opts = nil
  end
  opts = {} if opts.nil?
  exchange = exchange.is_a?(MQ::Exchange) ? exchange : MQ.direct(exchange,opts)
  raise "accepts only direct exchanges" unless exchange.type == :direct
  exchange
end

#get_queue(exchange, *args) ⇒ Object

can specify a key to create a queue for that subdomain



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ass.rb', line 41

def get_queue(exchange,*args)
  case args[0]
  when Hash
    key = nil
    opts = args[0]
  when String
    key = args[0]
    opts = args[1]
  end
  opts = {} if opts.nil?
  if key
    name = "#{exchange.name}--#{key}"
    q = MQ.queue(name,opts)
    q.bind(exchange,{ :routing_key => key})
  else
    q = MQ.queue(exchange.name,opts)
    q.bind(exchange,{ :routing_key => exchange.name })
  end
  q
end

#server(*args) ⇒ Object



21
22
23
# File 'lib/ass.rb', line 21

def server(*args)
  Server.new(@server_exchange,get_queue(@server_exchange,*args))
end