Class: BunnyHair::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_hair/exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, type, name, options = {}) ⇒ Exchange

Returns a new instance of Exchange.



7
8
9
10
11
12
# File 'lib/bunny_hair/exchange.rb', line 7

def initialize(connection, type, name, options={})
  @connection = connection
  @name = name
  @type = type
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/bunny_hair/exchange.rb', line 28

def method_missing(method, *args)
  method_name  = method.to_s
  is_predicate = false

  if method_name =~ /^(.*)\?$/
    return !!options[method_name.gsub('?', '').to_sym]
  end

  super
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/bunny_hair/exchange.rb', line 5

def connection
  @connection
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/bunny_hair/exchange.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/bunny_hair/exchange.rb', line 5

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/bunny_hair/exchange.rb', line 5

def type
  @type
end

Instance Method Details

#channelObject



18
19
20
# File 'lib/bunny_hair/exchange.rb', line 18

def channel
  Channel.new
end

#publish(message, options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/bunny_hair/exchange.rb', line 22

def publish(message, options={})
  queues.each do |queue|
    queue.receive(OpenStruct.new, OpenStruct.new, message)
  end
end

#queuesObject



14
15
16
# File 'lib/bunny_hair/exchange.rb', line 14

def queues
  @queues ||= []
end