Class: Slnky::Service::Exchanges

Inherits:
Object
  • Object
show all
Defined in:
lib/slnky/service/exchanges.rb

Instance Method Summary collapse

Constructor Details

#initialize(channel) ⇒ Exchanges



4
5
6
7
# File 'lib/slnky/service/exchanges.rb', line 4

def initialize(channel)
  @channel = channel
  @exchanges = {}
end

Instance Method Details

#[](name) ⇒ Object



22
23
24
# File 'lib/slnky/service/exchanges.rb', line 22

def [](name)
  @exchanges["slnky.#{name}"] || @exchanges[name] || raise("no exchange found: #{name}")
end

#create(name, overrides = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/slnky/service/exchanges.rb', line 9

def create(name, overrides={})
  options = {
      type: :fanout
  }.merge(overrides)
  @exchanges[name] =
      case options[:type]
        when :fanout
          @channel.fanout("slnky.#{name}")
        else
          raise "unknown exchange type: #{options[:type]}"
      end
end

#eachObject



26
27
28
29
30
# File 'lib/slnky/service/exchanges.rb', line 26

def each
  @exchanges.each do |name, exchange|
    yield name, exchange
  end
end