<commit_before>module Rrod
  module Model
    module Validations
      
      class AssociatedValidator < ActiveModel::EachValidator
        def validate_each(record, attribute, value)
          return if Array(value).collect{ |r| r.nil? || r.valid? }.all?
          record.errors.add(attribute, error_message_for(attribute, value))
        end

        private
   
        def error_message_for(attribute, associated_records)
          if associated_records.respond_to?(:each_with_index)
            record_errors = associated_records.enum_for(:each_with_index).collect do |record, index|
              next unless record.errors.any?
              record.errors.full_messages.to_sentence
            end
            record_errors.compact!
            record_errors.flatten!
            record_errors.join('; ')
          else
            associated_record.errrors.full_messages.to_sentence
          end
        end
      end
     
      module ClassMethods 

        def validates_associated(*attrs)
          validates_with AssociatedValidator, _merge_attributes(attrs)
        end

      end

    end
  end
end<commit_msg>Fixed typos.<commit_after>module Rrod
  module Model
    module Validations
      
      class AssociatedValidator < ActiveModel::EachValidator
        def validate_each(record, attribute, value)
          return if Array(value).collect{ |r| r.nil? || r.valid? }.all?
          record.errors.add(attribute, error_message_for(attribute, value))
        end

        private
   
        def error_message_for(attribute, associated_records)
          if associated_records.respond_to?(:each_with_index)
            record_errors = associated_records.enum_for(:each_with_index).collect do |record, index|
              next unless record.errors.any?
              record.errors.full_messages.to_sentence
            end
            record_errors.compact!
            record_errors.flatten!
            record_errors.join('; ')
          else
            associated_records.errors.full_messages.to_sentence
          end
        end
      end
     
      module ClassMethods 

        def validates_associated(*attrs)
          validates_with AssociatedValidator, _merge_attributes(attrs)
        end

      end

    end
  end
end
{'fraction_non_alphanumeric': 0.0670812972012439, 'fraction_numerical': 0.0, 'mean_word_length': 2.1408647140864714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '248878', 'n_tokens_mistral': 600, 'n_tokens_neox': 577, 'n_words': 120}