Class: Gecko::Errors
- Inherits:
-
Object
- Object
- Gecko::Errors
- Defined in:
- lib/gecko/helpers/validation_helper.rb
Instance Attribute Summary collapse
-
#messages ⇒ Hash
readonly
The hash of errors for this record.
Instance Method Summary collapse
-
#[](attribute) ⇒ Array
Fetch the errors for a specific attribute.
-
#clear ⇒ undefined
Clear the validation errors.
-
#empty? ⇒ Boolean
Whether there are any errors.
-
#from_response(error_hash) ⇒ undefined
private
Parse JSON errors response into the error object.
-
#initialize(base) ⇒ Errors
constructor
private
Set up the error object.
Constructor Details
#initialize(base) ⇒ Errors
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.
Set up the error object
38 39 40 41 |
# File 'lib/gecko/helpers/validation_helper.rb', line 38 def initialize(base) @base = base = {} end |
Instance Attribute Details
#messages ⇒ Hash (readonly)
The hash of errors for this record
33 34 35 |
# File 'lib/gecko/helpers/validation_helper.rb', line 33 def end |
Instance Method Details
#[](attribute) ⇒ Array
Fetch the errors for a specific attribute
54 55 56 |
# File 'lib/gecko/helpers/validation_helper.rb', line 54 def [](attribute) [attribute.to_sym] end |
#clear ⇒ undefined
Clear the validation errors
66 67 68 |
# File 'lib/gecko/helpers/validation_helper.rb', line 66 def clear .clear end |
#empty? ⇒ Boolean
Whether there are any errors
75 76 77 |
# File 'lib/gecko/helpers/validation_helper.rb', line 75 def empty? .all? { |_k, v| v&.empty? && !v.is_a?(String) } end |
#from_response(error_hash) ⇒ undefined
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.
Parse JSON errors response into the error object
87 88 89 90 91 |
# File 'lib/gecko/helpers/validation_helper.rb', line 87 def from_response(error_hash) error_hash.each do |attr, errors| [attr.to_sym] = errors end end |