<commit_before>module Rulix
  class ActiveRecordValidator
    attr_accessor :ruleset

    def initialize *args
      ruleset = args.first[:ruleset]

      self.ruleset = ruleset
    end

    def validate record
      unless Rulix::Validator.valid? record, ruleset
        errors = Rulix::Validator.errors record, ruleset

        reduce_errors_into record, errors
      end
    end

    def reduce_errors_into record, error_hash
      error_hash.reduce(record) do |subject, error|
        key, val = error

        if val.is_a? Hash
          reduce_errors_into record.send(key), val
        else
          val.flatten.map do |err|
            subject.errors.add key, err
          end
        end

        subject
      end
    end
  end
end<commit_msg>ActiveRecordValidator will now return false when validation fails, like it should<commit_after>module Rulix
  class ActiveRecordValidator
    attr_accessor :ruleset

    def initialize *args
      ruleset = args.first[:ruleset]

      self.ruleset = ruleset
    end

    def validate record
      if Rulix::Validator.valid? record, ruleset
        true
      else
        errors = Rulix::Validator.errors record, ruleset

        reduce_errors_into record, errors

        false
      end
    end

    def reduce_errors_into record, error_hash
      error_hash.reduce(record) do |subject, error|
        key, val = error

        if val.is_a? Hash
          reduce_errors_into record.send(key), val
        else
          val.flatten.map do |err|
            subject.errors.add key, err
          end
        end

        subject
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.05648665425201738, 'fraction_numerical': 0.0, 'mean_word_length': 2.024390243902439, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5611957', 'n_tokens_mistral': 464, 'n_tokens_neox': 448, 'n_words': 134}