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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Carrot

Returns a new instance of Carrot.



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

def initialize(opts = {})
  @opts = 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

Class Method Details

.defaultObject



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

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.



91
92
93
# File 'lib/carrot.rb', line 91

def Carrot.method_missing(meth, *args, &blk)
  Carrot.default.__send__(meth, *args, &blk)
end

Instance Method Details

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



52
53
54
# File 'lib/carrot.rb', line 52

def direct(name = 'amq.direct', opts = {})
  exchanges[name] ||= AMQP::Exchange.new(self, :direct, name, opts)
end

#exchangesObject



68
69
70
# File 'lib/carrot.rb', line 68

def exchanges
  @exchanges ||= {}
end

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



64
65
66
# File 'lib/carrot.rb', line 64

def fanout(name = 'amq.fanout', opts = {})
  exchanges[name] ||= AMQP::Exchange.new(self, :fanout, name, opts)
end

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



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

def headers(name = 'amq.match', opts = {})
  exchanges[name] ||= AMQP::Exchange.new(self, :headers, name, opts)
end

#queue(name, opts = {}) ⇒ Object



34
35
36
# File 'lib/carrot.rb', line 34

def queue(name, opts = {})
  queues[name] ||= AMQP::Queue.new(self, name, opts)
end

#queuesObject



48
49
50
# File 'lib/carrot.rb', line 48

def queues
  @queues ||= {}
end

#serverObject



38
39
40
# File 'lib/carrot.rb', line 38

def server
  @server ||= AMQP::Server.new(@opts)
end

#stopObject Also known as: reset



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

def stop
  server.close
  @server = nil
end

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



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

def topic(name = 'amq.topic', opts = {})
  exchanges[name] ||= AMQP::Exchange.new(self, :topic, name, opts)
end