class Gecko::Errors
Attributes
messages[R]
The hash of errors for this record
@return [Hash]
@api public
Public Class Methods
new(base)
click to toggle source
Set up the error object
@api private
# File lib/gecko/helpers/validation_helper.rb, line 38 def initialize(base) @base = base @messages = {} end
Public Instance Methods
[](attribute)
click to toggle source
Fetch the errors for a specific attribute
@example
product.errors[:name] #=> ["can't be blank"]
@params [Symbol] :attribute
@return [Array]
@api public
# File lib/gecko/helpers/validation_helper.rb, line 54 def [](attribute) messages[attribute.to_sym] end
clear()
click to toggle source
Clear the validation errors
@example
product.errors.clear
@return [undefined]
@api public
# File lib/gecko/helpers/validation_helper.rb, line 66 def clear @messages.clear end
empty?()
click to toggle source
Whether there are any errors
@return [Boolean]
@api public
# File lib/gecko/helpers/validation_helper.rb, line 75 def empty? messages.all? { |_k, v| v&.empty? && !v.is_a?(String) } end
from_response(error_hash)
click to toggle source
Parse JSON errors response into the error object
@params [#to_hash] :error_hash hash of errors where key is an attribute
name and value is an array of error strings
@return [undefined]
@api private
# File lib/gecko/helpers/validation_helper.rb, line 87 def from_response(error_hash) error_hash.each do |attr, errors| @messages[attr.to_sym] = errors end end