Module: Liebre::Common::Utils

Defined in:
lib/liebre/common/utils.rb

Constant Summary collapse

@@mutex =
Mutex.new

Class Method Summary collapse

Class Method Details

.create_exchange(channel, config) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/liebre/common/utils.rb', line 13

def self.create_exchange channel, config
  exchange_name = config.fetch "name"
  
  type = config.fetch("type")
  opts = config.fetch("opts", {})
  exchange_opts = symbolize_keys(opts.merge("type" => type))
  
  mutex_sync { channel.exchange exchange_name, exchange_opts }
end

.mutex_syncObject



7
8
9
10
11
# File 'lib/liebre/common/utils.rb', line 7

def self.mutex_sync
  @@mutex.synchronize do
    yield
  end
end

.symbolize_keys(hash) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/liebre/common/utils.rb', line 23

def self.symbolize_keys hash
  result = {}
  hash.each do |k, v|
    result[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v
  end
  result
end