class Mutations::DefaultErrorMessageCreator

Offers a non-localized, english only, non configurable way to get error messages. This probably isnt good enough for users as-is.

Constants

MESSAGES

Public Instance Methods

message(key, error_symbol, options = {}) click to toggle source

key: the name of the field, eg, :email. Could be nil if it's an array element error_symbol: the validation symbol, eg, :matches or :required options:

:index -- index of error if it's in an array
# File lib/mutations/errors.rb, line 48
def message(key, error_symbol, options = {})
  if options[:index]
    "#{titleize(key || 'array')}[#{options[:index]}] #{MESSAGES[error_symbol]}"
  else
    "#{titleize(key)} #{MESSAGES[error_symbol]}"
  end
end
titleize(key) click to toggle source
# File lib/mutations/errors.rb, line 56
def titleize(key)
  key = key.to_s.downcase
  if key == "id"
    "ID"
  elsif key.end_with?("_id")
    "#{key.titleize} ID"
  else
    key.titleize
  end
end