Module: FormattedErrors

Defined in:
lib/eipiai/validation/concerns/formatted_errors.rb

Overview

FormattedErrors

copy/paste of the github.com/blendle/formatted_errors gem, until that gem is made open source.

Class Method Summary collapse

Class Method Details

.parse(*errors) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/eipiai/validation/concerns/formatted_errors.rb', line 8

def parse(*errors)
  # First check for array, don't switch these lines as the hash is converted to
  # an array
  errors = errors.flatten(1) if errors.length == 1 && errors.first.is_a?(Array)
  errors = errors.first if errors.length == 1 && errors.first.is_a?(Hash)

  errors = errors.map do |key, value|
    parse_single(key, **value || {})
  end

  { _errors: errors }
end