edge badge

Active Model Error

Represents one single error

Methods
#
A
D
E
F
H
I
M
N
S
Constants
CALLBACKS_OPTIONS = [:if, :unless, :on, :allow_nil, :allow_blank, :strict]
 
MESSAGE_OPTIONS = [:message]
 
Attributes
[R] attribute
[R] base
[R] options
[R] raw_type
[R] type
Class Public methods
new(base, attribute, type = :invalid, **options)
# File activemodel/lib/active_model/error.rb, line 98
def initialize(base, attribute, type = :invalid, **options)
  @base = base
  @attribute = attribute
  @raw_type = type
  @type = type || :invalid
  @options = options
end
Instance Public methods
==(other)
Also aliased as: eql?
# File activemodel/lib/active_model/error.rb, line 153
def ==(other)
  other.is_a?(self.class) && attributes_for_hash == other.attributes_for_hash
end
detail()
# File activemodel/lib/active_model/error.rb, line 124
def detail
  { error: raw_type }.merge(options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS))
end
eql?(other)
Alias for: ==
full_message()
# File activemodel/lib/active_model/error.rb, line 128
def full_message
  self.class.full_message(attribute, message, @base.class)
end
hash()
# File activemodel/lib/active_model/error.rb, line 158
def hash
  attributes_for_hash.hash
end
initialize_dup(other)
# File activemodel/lib/active_model/error.rb, line 106
def initialize_dup(other)
  @attribute = @attribute.dup
  @raw_type = @raw_type.dup
  @type = @type.dup
  @options = @options.deep_dup
end
match?(attribute, type = nil, **options)

See if error matches provided attribute, type and options.

# File activemodel/lib/active_model/error.rb, line 133
def match?(attribute, type = nil, **options)
  if @attribute != attribute || (type && @type != type)
    return false
  end

  options.each do |key, value|
    if @options[key] != value
      return false
    end
  end

  true
end
message()
# File activemodel/lib/active_model/error.rb, line 115
def message
  case raw_type
  when Symbol
    self.class.generate_message(attribute, raw_type, @base, options.except(*CALLBACKS_OPTIONS))
  else
    raw_type
  end
end
strict_match?(attribute, type, **options)
# File activemodel/lib/active_model/error.rb, line 147
def strict_match?(attribute, type, **options)
  return false unless match?(attribute, type)

  options == @options.except(*CALLBACKS_OPTIONS + MESSAGE_OPTIONS)
end
Instance Protected methods
attributes_for_hash()
# File activemodel/lib/active_model/error.rb, line 163
def attributes_for_hash
  [@base, @attribute, @raw_type, @options.except(*CALLBACKS_OPTIONS)]
end