Class: EasyTalk::SchemaErrorsMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_talk/schema_errors_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(errors) ⇒ SchemaErrorsMapper

Returns a new instance of SchemaErrorsMapper.



5
6
7
# File 'lib/easy_talk/schema_errors_mapper.rb', line 5

def initialize(errors)
  @errors = errors.to_a
end

Instance Method Details

#errorsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/easy_talk/schema_errors_mapper.rb', line 9

def errors
  @errors.each_with_object({}) do |error, hash|
    if error['data_pointer'].present?
      key = error['data_pointer'].split('/').compact_blank.join('.')
      hash[key] = error['error']
    else
      error['details']['missing_keys'].each do |missing_key|
        message = "#{error['error'].split(':').first}: #{missing_key}"
        hash[missing_key] = message
      end
    end
  end
end