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
17 18 19 20 21 22 23 24 25 |
# File 'lib/liebre/common/utils.rb', line 17 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_sync ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/liebre/common/utils.rb', line 7 def self.mutex_sync unless @@mutex.locked? @@mutex.synchronize do yield end else yield end end |
.symbolize_keys(hash) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/liebre/common/utils.rb', line 27 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 |