Class: StoreModel::CombineErrorsStrategies::MergeArrayErrorStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb

Overview

MergeArrayErrorStrategy copies errors from the StoreModel::Model to the parent record attribute errors.

Instance Method Summary collapse

Instance Method Details

#call(attribute, base_errors, store_models) ⇒ Object

Merges errors on attribute from the child model with parent errors.

Parameters:

  • attribute (String)

    name of the validated attribute

  • base_errors (ActiveModel::Errors)

    errors object of the parent record

  • store_models (Array)

    an array or store_models that have been validated



13
14
15
16
17
18
19
# File 'lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb', line 13

def call(attribute, base_errors, store_models)
  store_models.each_with_index do |store_model, index|
    store_model.errors.full_messages.each do |full_message|
      base_errors.add(attribute, :invalid, message: "[#{index}] #{full_message}")
    end
  end
end