Method: PureValidator::ValidationErrors#to_hash

Defined in:
lib/pure_validator/validation_errors.rb

#to_hash(full_messages = false) ⇒ Object

Returns a Hash of attributes with their error messages. If full_messages is true, it will contain full messages (see full_message).

errors.to_hash       # => {:name=>["can not be nil"]}
errors.to_hash(true) # => {:name=>["name can not be nil"]}


154
155
156
157
158
159
160
161
162
163
164
# File 'lib/pure_validator/validation_errors.rb', line 154

def to_hash(full_messages = false)
  if full_messages
    messages = {}
    self.messages.each do |attribute, array|
      messages[attribute] = array.map { |message| full_message(attribute, message) }
    end
    messages
  else
    self.messages.dup
  end
end