class ActiveModel::BetterErrors::ErrorMessage

ErrorMessage

Constants

CALLBACKS_OPTIONS

Attributes

attribute[R]
base[R]
message[R]
options[R]
type[R]

Public Class Methods

build(base, attribute, message, options = nil) click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 45
def self.build(base, attribute, message, options = nil)
  options   = options ? options : {}
  options   = options.except(*CALLBACKS_OPTIONS)

  symbol, string = identify message, options.delete(:message)

  new(base, attribute, symbol, string, options)
end
identify(message, override) click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 28
def self.identify(message, override)
  symbol = string = nil

  message   = normalize message
  override  = normalize override

  symbol = message if message.is_a?(Symbol)
  symbol = override if override.is_a?(Symbol)

  string = message if message.is_a?(String)
  string = override if override.is_a?(String)

  string = nil if string.blank?

  [symbol, string]
end
new(base, attribute, type, message, options = {}) click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 56
def initialize(base, attribute, type, message, options = {})
  @base       = base
  @attribute  = attribute
  @type       = type
  @message    = message
  @options    = options
end
normalize(message) click to toggle source

return the message either as nil, symbol, or string

# File lib/active_model/better_errors/error_message.rb, line 15
def self.normalize(message)
  case message
  when nil
    nil
  when Symbol
    message
  when Proc
    message.call
  else
    message.to_s
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 64
def <=>(other)
  to_hash <=> other.to_hash
end
==(other) click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 93
def ==(other)
  return type == other if other.is_a?(Symbol)
  to_s == other.to_s
end
as_json(*json_args) click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 77
def as_json(*json_args)
  to_hash
end
hash() click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 81
def hash
  to_hash.hash
end
inspect() click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 89
def inspect
  to_s.inspect
end
to_hash() click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 68
def to_hash
  {
    attribute: attribute,
    type:      type,
    message:   message,
    options:   options
  }
end
to_s() click to toggle source
# File lib/active_model/better_errors/error_message.rb, line 85
def to_s
  ::ActiveModel::BetterErrors.format_message(base, self)
end