Module: Confium::Errors::Coerce

Defined in:
lib/confium/errors/coerce.rb

Class Method Summary collapse

Class Method Details

.args(message, details_hash, kwargs) ⇒ Object

Normalize the (message, details_hash, kwargs) triple that every typed-error initializer receives. Returns [message, kwargs] where:

  • message is nil or a String (never a Hash)
  • kwargs is a Hash with symbol keys, containing every key from the original details_hash and **kwargs, plus anything that was tucked inside message (when the caller passed a Hash as the first arg).

The subclass initializer then kwargs.delete(:specific_field) to pull its own fields out, and the leftover **kwargs flows to super as details:.



37
38
39
40
41
42
43
44
45
46
# File 'lib/confium/errors/coerce.rb', line 37

def args(message, details_hash, kwargs)
  if message.is_a?(Hash)
    kwargs = message.transform_keys(&:to_sym).merge(kwargs)
    message = kwargs.delete(:message)
  end
  if details_hash.is_a?(Hash)
    kwargs = details_hash.transform_keys(&:to_sym).merge(kwargs)
  end
  [message, kwargs]
end