Class: Knight::Error
- Inherits:
-
Object
- Object
- Knight::Error
- Defined in:
- lib/knight/error.rb
Overview
A representation of an error
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
private
Object under validation.
-
#rule ⇒ Rule
readonly
private
Broken rule.
Instance Method Summary collapse
-
#attribute_name ⇒ String
private
Return error attribute name.
-
#initialize(rule, resource) ⇒ Error
constructor
private
Initialize an error.
-
#message ⇒ String
Return formatted error message.
-
#value ⇒ Object
private
Return error value.
Constructor Details
#initialize(rule, resource) ⇒ 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 an error
31 32 33 34 |
# File 'lib/knight/error.rb', line 31 def initialize(rule, resource) @rule = rule @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
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.
Object under validation
21 22 23 |
# File 'lib/knight/error.rb', line 21 def resource @resource end |
#rule ⇒ Rule (readonly)
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.
Broken rule
14 15 16 |
# File 'lib/knight/error.rb', line 14 def rule @rule end |
Instance Method Details
#attribute_name ⇒ String
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.
Return error attribute name
53 54 55 |
# File 'lib/knight/error.rb', line 53 def attribute_name rule.attribute_name end |
#message ⇒ String
Return formatted error message
44 45 46 |
# File 'lib/knight/error.rb', line 44 def rule. % rule.to_hash.merge(value: value) end |
#value ⇒ Object
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.
Return error value
62 63 64 |
# File 'lib/knight/error.rb', line 62 def value resource.public_send(attribute_name) if resource.respond_to?(attribute_name) end |