Class: Carrot
- Inherits:
-
Object
show all
- Defined in:
- lib/carrot.rb,
lib/carrot.rb,
lib/carrot.rb
Overview
– convenience wrapper (read: HACK) for thread-local Carrot object
Defined Under Namespace
Modules: AMQP
Classes: Error
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Carrot
Returns a new instance of Carrot.
32
33
34
|
# File 'lib/carrot.rb', line 32
def initialize(opts = {})
@server = AMQP::Server.new(opts)
end
|
Class Attribute Details
.logging ⇒ Object
Returns the value of attribute logging.
23
24
25
|
# File 'lib/carrot.rb', line 23
def logging
@logging
end
|
Instance Attribute Details
#server ⇒ Object
Returns the value of attribute server.
30
31
32
|
# File 'lib/carrot.rb', line 30
def server
@server
end
|
Class Method Details
.default ⇒ Object
80
81
82
83
|
# File 'lib/carrot.rb', line 80
def Carrot.default
Thread.current[:carrot] ||= Carrot.new
end
|
.logging? ⇒ Boolean
25
26
27
|
# File 'lib/carrot.rb', line 25
def self.logging?
@logging
end
|
.method_missing(meth, *args, &blk) ⇒ Object
Allows for calls to all Carrot instance methods. This implicitly calls Carrot.new so that a new channel is allocated for subsequent operations.
87
88
89
|
# File 'lib/carrot.rb', line 87
def Carrot.method_missing(meth, *args, &blk)
Carrot.default.__send__(meth, *args, &blk)
end
|
Instance Method Details
#direct(name = 'amq.direct', opts = {}) ⇒ Object
48
49
50
|
# File 'lib/carrot.rb', line 48
def direct(name = 'amq.direct', opts = {})
exchanges[name] ||= AMQP::Exchange.new(self, :direct, name, opts)
end
|
#exchanges ⇒ Object
64
65
66
|
# File 'lib/carrot.rb', line 64
def exchanges
@exchanges ||= {}
end
|
#fanout(name = 'amq.fanout', opts = {}) ⇒ Object
56
57
58
|
# File 'lib/carrot.rb', line 56
def fanout(name = 'amq.fanout', opts = {})
exchanges[name] ||= AMQP::Exchange.new(self, :fanout, name, opts)
end
|
60
61
62
|
# File 'lib/carrot.rb', line 60
def (name = 'amq.match', opts = {})
exchanges[name] ||= AMQP::Exchange.new(self, :headers, name, opts)
end
|
#queue(name, opts = {}) ⇒ Object
36
37
38
|
# File 'lib/carrot.rb', line 36
def queue(name, opts = {})
queues[name] ||= AMQP::Queue.new(self, name, opts)
end
|
#queues ⇒ Object
44
45
46
|
# File 'lib/carrot.rb', line 44
def queues
@queues ||= {}
end
|
#stop ⇒ Object
40
41
42
|
# File 'lib/carrot.rb', line 40
def stop
server.close
end
|
#topic(name = 'amq.topic', opts = {}) ⇒ Object
52
53
54
|
# File 'lib/carrot.rb', line 52
def topic(name = 'amq.topic', opts = {})
exchanges[name] ||= AMQP::Exchange.new(self, :topic, name, opts)
end
|