class Sneakers::Configuration

Constants

DEFAULTS
EXCHANGE_OPTION_DEFAULTS
QUEUE_OPTION_DEFAULTS

Public Class Methods

new() click to toggle source
# File lib/sneakers/configuration.rb, line 52
def initialize
  clear
end

Public Instance Methods

clear() click to toggle source
# File lib/sneakers/configuration.rb, line 56
def clear
  @hash = DEFAULTS.dup
  @hash[:amqp]  = ENV.fetch('RABBITMQ_URL', 'amqp://guest:guest@localhost:5672')
  @hash[:vhost] = AMQ::Settings.parse_amqp_url(@hash[:amqp]).fetch(:vhost, '/')
end
deep_merge(first, second) click to toggle source
# File lib/sneakers/configuration.rb, line 120
def deep_merge(first, second)
  merger = proc { |_, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
  first.merge(second, &merger)
end
inspect()
Also aliased as: inspect_without_redaction
inspect_with_redaction() click to toggle source
# File lib/sneakers/configuration.rb, line 93
def inspect_with_redaction
  redacted = self.class.new
  redacted.merge! to_hash

  # redact passwords
  redacted[:amqp] = redacted[:amqp].sub(/(?<=\Aamqp:\/)[^@]+(?=@)/, "<redacted>") if redacted.has_key?(:amqp)
  return redacted.inspect_without_redaction
end
Also aliased as: inspect
inspect_without_redaction()
Alias for: inspect
map_all_deprecated_options(hash) click to toggle source
# File lib/sneakers/configuration.rb, line 104
def map_all_deprecated_options(hash)
  hash = map_deprecated_options_key(:exchange_options, :exchange_type, :type, true, hash)
  hash = map_deprecated_options_key(:exchange_options, :exchange_arguments, :arguments, true, hash)
  hash = map_deprecated_options_key(:exchange_options, :durable, :durable, false, hash)
  hash = map_deprecated_options_key(:queue_options, :durable, :durable, true, hash)
  hash = map_deprecated_options_key(:queue_options, :arguments, :arguments, true, hash)
  hash
end
map_deprecated_options_key(target_key, deprecated_key, key, delete_deprecated_key, hash = {}) click to toggle source
# File lib/sneakers/configuration.rb, line 113
def map_deprecated_options_key(target_key, deprecated_key, key, delete_deprecated_key, hash = {})
  return hash if hash[deprecated_key].nil?
  hash = deep_merge({ target_key => { key => hash[deprecated_key] } }, hash)
  hash.delete(deprecated_key) if delete_deprecated_key
  hash
end
merge(hash) click to toggle source
# File lib/sneakers/configuration.rb, line 86
def merge(hash)
  instance = self.class.new
  instance.merge! to_hash
  instance.merge! hash
  instance
end
merge!(hash) click to toggle source
# File lib/sneakers/configuration.rb, line 62
def merge!(hash)
  hash = hash.dup
  hash = map_all_deprecated_options(hash)

  # parse vhost from amqp if vhost is not specified explicitly, only
  # if we're not given a connection to use.
  if hash[:connection].nil?
    if hash[:vhost].nil? && !hash[:amqp].nil?
      hash[:vhost] = AMQ::Settings.parse_amqp_url(hash[:amqp]).fetch(:vhost, '/')
    end
  else
    # If we are given a Bunny object, ignore params we'd otherwise use to
    # create one.  This removes any question about where config params are
    # coming from, and makes it more likely that downstream code that needs
    # this info gets it from the right place.
    [:vhost, :amqp, :heartbeat].each do |k|
      hash.delete(k)
      @hash.delete(k)
    end
  end

  @hash = deep_merge(@hash, hash)
end