Class: Promiscuous::AMQP::Fake

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/amqp/fake.rb

Defined Under Namespace

Modules: Subscriber

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messagesObject

Returns the value of attribute messages.



2
3
4
# File 'lib/promiscuous/amqp/fake.rb', line 2

def messages
  @messages
end

Class Method Details

.backendObject



5
6
7
# File 'lib/promiscuous/amqp/fake.rb', line 5

def backend
  Promiscuous::AMQP.backend
end

Instance Method Details

#connectObject



11
12
13
# File 'lib/promiscuous/amqp/fake.rb', line 11

def connect
  @messages = []
end

#connected?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/promiscuous/amqp/fake.rb', line 18

def connected?
  true
end

#disconnectObject



15
16
# File 'lib/promiscuous/amqp/fake.rb', line 15

def disconnect
end

#get_next_messageObject



32
33
34
# File 'lib/promiscuous/amqp/fake.rb', line 32

def get_next_message
  @messages.shift
end

#get_next_payloadObject



36
37
38
39
# File 'lib/promiscuous/amqp/fake.rb', line 36

def get_next_payload
  msg = get_next_message
  msg && JSON.parse(msg[:payload])
end

#num_messagesObject



28
29
30
# File 'lib/promiscuous/amqp/fake.rb', line 28

def num_messages
  @messages.count
end

#publish(options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/promiscuous/amqp/fake.rb', line 22

def publish(options={})
  Promiscuous.debug "[publish (fake)] #{options[:exchange].try(:name) || "default"}/#{options[:key]} #{options[:payload]}"
  @messages << options
  options[:on_confirm].try(:call)
end