Class: Carrot

Inherits:
Object
  • Object
show all
Defined in:
lib/secure_carrot.rb,
lib/secure_carrot.rb,
lib/secure_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.



31
32
33
# File 'lib/secure_carrot.rb', line 31

def initialize(opts = {})
  @opts = opts
end

Class Attribute Details

.loggingObject

Returns the value of attribute logging.



24
25
26
# File 'lib/secure_carrot.rb', line 24

def logging
  @logging
end

Class Method Details

.defaultObject



81
82
83
84
# File 'lib/secure_carrot.rb', line 81

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

.logging?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/secure_carrot.rb', line 26

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.



88
89
90
# File 'lib/secure_carrot.rb', line 88

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

Instance Method Details

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



53
54
55
# File 'lib/secure_carrot.rb', line 53

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

#exchangesObject



65
66
67
# File 'lib/secure_carrot.rb', line 65

def exchanges
  @exchanges ||= {}
end

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



61
62
63
# File 'lib/secure_carrot.rb', line 61

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

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



35
36
37
# File 'lib/secure_carrot.rb', line 35

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

#queuesObject



49
50
51
# File 'lib/secure_carrot.rb', line 49

def queues
  @queues ||= {}
end

#serverObject



39
40
41
# File 'lib/secure_carrot.rb', line 39

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

#stopObject Also known as: reset



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

def stop
  server.close
  @server = nil
end

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



57
58
59
# File 'lib/secure_carrot.rb', line 57

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