Module: Reality::Options

Defined in:
lib/reality/options.rb

Class Method Summary collapse

Class Method Details

.check(options, valid_options, logging_container = nil, method_descriptor = nil) ⇒ Object

Set the levels on an array of loggers. The levels parameter must be an array matching the number of loggers supplied or a single level. If a block is supplied then the levels are set to the specified values for the duration of the block and then reset to original values after the block completes.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/reality/options.rb', line 22

def check(options, valid_options, logging_container = nil, method_descriptor = nil)
  bad_options = options.keys.select { |k| !valid_options.include?(k) }
  return if bad_options.empty?

  single_error = bad_options.size == 1
  message = "Unknown option#{single_error ? '' : 's'} #{single_error ? "'#{bad_options.first.inspect}'" : bad_options.inspect} passed to #{method_descriptor || 'method'}"
  if logging_container
    logging_container.error(message)
  else
    raise ArgumentError.new(message)
  end
end