Sha256: e382fa2e1b83e78355336cdcbc3fb067ed1e2376a7a321a39956c6097317553f
Contents?: true
Size: 1.13 KB
Versions: 12
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true # Taken from https://github.com/trailblazer/reform-rails/issues/86#issuecomment-763120151 # rubocop:disable Metrics/CyclomaticComplexity # rubocop:disable Lint/UselessAssignment module Reform class Contract < Disposable::Twin class Result private # this doesn't do nested errors (e.g. ) def filter_for(method, *args) @results.collect { |r| r.public_send(method, *args).to_h } .inject({}) { |hah, err| hah.merge(err) { |_key, old_v, new_v| (new_v.is_a?(Array) ? (old_v |= new_v) : old_v.merge(new_v)) } } .find_all do |_k, v| # filter :nested=>{:something=>["too nested!"]} #DISCUSS: do we want that here? if v.is_a?(Hash) nested_errors = v.select { |attr_key, val| attr_key.is_a?(Integer) && val.is_a?(Array) && val.any? } v = nested_errors.to_a if nested_errors.any? end v.is_a?(ActiveModel::DeprecationHandlingMessageArray) end.to_h end end end end # rubocop:enable Metrics/CyclomaticComplexity # rubocop:disable Lint/UselessAssignment
Version data entries
12 entries across 12 versions & 1 rubygems