Sha256: 51571d4771ea663f6ebca19d33c6a4163a686a023bdf7fe4589e6edb638fd1ab

Contents?: true

Size: 551 Bytes

Versions: 12

Compression:

Stored size: 551 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module AttributeObject
    class NestedValidator < ActiveModel::EachValidator # :nodoc:
      def validate_each(record, attribute, value)
        value = value.values if value.is_a?(Hash)
        return unless Array(value).reject { |r| valid_object?(r) }.any?

        record.errors.add(attribute, :invalid, **options.merge(value: value))
      end

      private

      def valid_object?(record)
        return true unless record.respond_to?(:valid?)

        record.valid?
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.8 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.7 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.6 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.5 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.4 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.3 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.2 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.1 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.0 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.0.rc2 lib/decidim/attribute_object/nested_validator.rb
decidim-core-0.27.0.rc1 lib/decidim/attribute_object/nested_validator.rb