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
36 37 38 39 |
# File 'lib/gecko/helpers/validation_helper.rb', line 36 def initialize(base) @base = base = {} end |
Instance Attribute Details
#messages ⇒ Hash (readonly)
The hash of errors for this record
31 32 33 |
# File 'lib/gecko/helpers/validation_helper.rb', line 31 def end |
Instance Method Details
#[](attribute) ⇒ Array
Fetch the errors for a specific attribute
52 53 54 |
# File 'lib/gecko/helpers/validation_helper.rb', line 52 def [](attribute) [attribute.to_sym] end |
#clear ⇒ undefined
Clear the validation errors
64 65 66 |
# File 'lib/gecko/helpers/validation_helper.rb', line 64 def clear .clear end |
#empty? ⇒ Boolean
Whether there are any errors
73 74 75 |
# File 'lib/gecko/helpers/validation_helper.rb', line 73 def empty? .all? { |k, v| 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
85 86 87 88 89 |
# File 'lib/gecko/helpers/validation_helper.rb', line 85 def from_response(error_hash) error_hash.each do |attr, errors| [attr.to_sym] = errors end end |