Sha256: 4c61bc7fc7c19e5e51ddecad559a72c2535fb0a7f338c15d7a8473f8ea4fd8ab

Contents?: true

Size: 878 Bytes

Versions: 35

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

module StoreModel
  module CombineErrorsStrategies
    # +MergeArrayErrorStrategy+ copies errors from the StoreModel::Model to the parent
    # record attribute errors.
    class MergeArrayErrorStrategy
      # Merges errors on +attribute+ from the child model with parent errors.
      #
      # @param attribute [String] name of the validated attribute
      # @param base_errors [ActiveModel::Errors] errors object of the parent record
      # @param store_models [Array] an array or store_models that have been validated
      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
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
store_model-4.2.1 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-4.2.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-4.1.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-4.0.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-3.0.2 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-3.0.1 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-3.0.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.4.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.3.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.2.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.1.2 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.1.1 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.1.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.0.1 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-2.0.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-1.6.2 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-1.6.1 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-1.6.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-1.5.1 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb
store_model-1.5.0 lib/store_model/combine_errors_strategies/merge_array_error_strategy.rb