Class: Carrot

Inherits:
Object
  • 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

.loggingObject

Returns the value of attribute logging.



23
24
25
# File 'lib/carrot.rb', line 23

def logging
  @logging
end

Instance Attribute Details

#serverObject

Returns the value of attribute server.



30
31
32
# File 'lib/carrot.rb', line 30

def server
  @server
end

Class Method Details

.defaultObject



76
77
78
79
# File 'lib/carrot.rb', line 76

def Carrot.default
  #-- XXX clear this when connection is closed
  Thread.current[:carrot] ||= Carrot.new
end

.logging?Boolean

Returns:

  • (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.



83
84
85
# File 'lib/carrot.rb', line 83

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

#exchangesObject



60
61
62
# File 'lib/carrot.rb', line 60

def exchanges
  @exchanges ||= {}
end

#headers(name = 'amq.match', opts = {}) ⇒ Object



56
57
58
# File 'lib/carrot.rb', line 56

def headers(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

#queuesObject



44
45
46
# File 'lib/carrot.rb', line 44

def queues
  @queues ||= {}
end

#stopObject



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