Class: Lotus::Validations::Error
- Inherits:
-
Object
- Object
- Lotus::Validations::Error
- Defined in:
- lib/lotus/validations/error.rb
Overview
A single validation error for an attribute
Constant Summary collapse
- NAMESPACE_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'.'.freeze
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
The actual value.
-
#attribute ⇒ Object
Returns the namespaced attribute name.
-
#attribute_name ⇒ Symbol
readonly
The name of the attribute.
-
#expected ⇒ Object
readonly
The expected value.
-
#validation ⇒ Symbol
readonly
The name of the validation.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Check if self equals to ‘other`.
-
#initialize(attribute_name, validation, expected, actual, namespace = nil) ⇒ Error
constructor
private
Initialize a validation error.
Constructor Details
#initialize(attribute_name, validation, expected, actual, namespace = nil) ⇒ Error
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a validation error
74 75 76 77 78 79 80 81 |
# File 'lib/lotus/validations/error.rb', line 74 def initialize(attribute_name, validation, expected, actual, namespace = nil) @attribute_name = attribute_name.to_s @validation = validation @expected = expected @actual = actual @namespace = namespace @attribute = [@namespace, attribute_name].compact.join(NAMESPACE_SEPARATOR) end |
Instance Attribute Details
#actual ⇒ Object (readonly)
The actual value
45 46 47 |
# File 'lib/lotus/validations/error.rb', line 45 def actual @actual end |
#attribute ⇒ Object
Returns the namespaced attribute name
In cases where the error was pulled up from nested validators, ‘attribute` will be a namespaced string containing parent attribute names separated by a period.
62 63 64 |
# File 'lib/lotus/validations/error.rb', line 62 def attribute @attribute end |
#attribute_name ⇒ Symbol (readonly)
The name of the attribute
24 25 26 |
# File 'lib/lotus/validations/error.rb', line 24 def attribute_name @attribute_name end |
#expected ⇒ Object (readonly)
The expected value
38 39 40 |
# File 'lib/lotus/validations/error.rb', line 38 def expected @expected end |
#validation ⇒ Symbol (readonly)
The name of the validation
31 32 33 |
# File 'lib/lotus/validations/error.rb', line 31 def validation @validation end |
Instance Method Details
#==(other) ⇒ Object
Check if self equals to ‘other`
86 87 88 89 90 91 92 |
# File 'lib/lotus/validations/error.rb', line 86 def ==(other) other.is_a?(self.class) && other.attribute == attribute && other.validation == validation && other.expected == expected && other.actual == actual end |