module Mongo::Utils

@api private

Public Instance Methods

camelize(sym) click to toggle source
# File lib/mongo/utils.rb, line 69
                def camelize(sym)
  sym.to_s.gsub(/_(\w)/) { $1.upcase }
end
excerpt_backtrace(exc, **opts) click to toggle source

@option opts [ true | false | nil | Integer ] :bg_error_backtrace

Experimental. Set to true to log complete backtraces for errors in
background threads. Set to false or nil to not log backtraces. Provide
a positive integer to log up to that many backtrace lines.
# File lib/mongo/utils.rb, line 47
                def excerpt_backtrace(exc, **opts)
  case lines = opts[:bg_error_backtrace]
  when Integer
    ":\n#{exc.backtrace[0..lines].join("\n")}"
  when false, nil
    nil
  else
    ":\n#{exc.backtrace.join("\n")}"
  end
end
shallow_camelize_keys(hash) click to toggle source

Stringifies the keys in the provided hash and converts underscore style keys to camel case style keys.

# File lib/mongo/utils.rb, line 65
                def shallow_camelize_keys(hash)
  Hash[hash.map { |k, v| [camelize(k), v] }]
end
shallow_symbolize_keys(hash) click to toggle source

Symbolizes the keys in the provided hash.

# File lib/mongo/utils.rb, line 59
                def shallow_symbolize_keys(hash)
  Hash[hash.map { |k, v| [k.to_sym, v] }]
end
warn_bg_exception(msg, exc, **opts) click to toggle source

@option opts [ true | false | nil | Integer ] :bg_error_backtrace

Experimental. Set to true to log complete backtraces for errors in
background threads. Set to false or nil to not log backtraces. Provide
a positive integer to log up to that many backtrace lines.

@option opts [ Logger ] :logger A custom logger to use. @option opts [ String ] :log_prefix A custom log prefix to use when

logging.
# File lib/mongo/utils.rb, line 37
                def warn_bg_exception(msg, exc, **opts)
  bt_excerpt = excerpt_backtrace(exc, **opts)
  logger = LocalLogger.new(**opts)
  logger.log_warn("#{msg}: #{exc.class}: #{exc}#{bt_excerpt}")
end