Module: Moon::DataModel::MessageFormat

Included in:
TypeValidators::Base, Validators::Base
Defined in:
lib/data_model/message_format.rb

Overview

Utility module for formatting debug context information

Instance Method Summary collapse

Instance Method Details

#format_err(msg, ctx = {}) ⇒ String

Formats an error message to add more contextual info

Parameters:

  • msg (String)
  • ctx (Hash<Symbol, Object>) (defaults to: {})

Options Hash (ctx):

  • :key (Symbol)
  • :prefix (String)

Returns:

  • (String)

12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/data_model/message_format.rb', line 12

def format_err(msg, ctx = {})
  result = msg.dup
  if ctx
    if k = ctx[:key]
      result = "#{k.inspect} #{result}"
    end
    if p = ctx[:prefix]
      result = "#{prefix}: #{result}"
    end
  end
  result
end