<commit_before>module ActiveModel
  module ErrorCollecting
    class Errors
      MODEL_METHODS = [
        :clear, :has_key?, :get, :set, :delete, :[], :[]=,
        :each, :size, :values, :keys, :count, :empty?,
        :added?, :add, :add_on_empty, :add_on_blank
      ]

      HUMAN_REPORTER_METHODS = [
        :full_messages, :full_message, :generate_messages
      ]

      delegate *MODEL_METHODS,  to: :error_collection
      delegate *HUMAN_REPORTER_METHODS,  to: :human_reporter
      delegate :to_hash, to: :hash_reporter
      delegate :to_a, to: :array_reporter

      alias_method :blank?, :empty?

      attr_accessor :error_collection, :human_reporter, :hash_reporter, :array_reporter

      def initialize(base, options={})
        @base = base
        @error_collection = ErrorCollection.new
        create_reporters options[:reporters]
      end

      def create_reporters(reporters)
        @human_reporter = reporters[:human].new(error_collection)
        @hash_reporter = reporters[:hash].new(error_collection)
        @array_reporter = reporters[:array].new(error_collection)
      end

      def to_xml(options={})
        to_a.to_xml options.reverse_merge(:root => "errors", :skip_types => true)
      end

      def as_json(options=nil)
        to_hash
      end
    end
  end
end<commit_msg>add_on_blank and add_on_empty need to be on top level errors<commit_after>module ActiveModel
  module ErrorCollecting
    class Errors
      MODEL_METHODS = [
        :clear, :has_key?, :get, :set, :delete, :[], :[]=,
        :each, :size, :values, :keys, :count, :empty?,
        :added?, :add
      ]

      HUMAN_REPORTER_METHODS = [
        :full_messages, :full_message, :generate_messages
      ]

      delegate *MODEL_METHODS,  to: :error_collection
      delegate *HUMAN_REPORTER_METHODS,  to: :human_reporter
      delegate :to_hash, to: :hash_reporter
      delegate :to_a, to: :array_reporter

      alias_method :blank?, :empty?

      attr_accessor :error_collection, :human_reporter, :hash_reporter, :array_reporter

      def initialize(base, options={})
        @base = base
        @error_collection = ErrorCollection.new
        create_reporters options[:reporters]
      end

      def add_on_blank(attributes, hash)
        [*attributes].each do |attribute|
          error_collection.add(attribute, [:blank, hash[:message]]) if @base.send(attribute).blank?
        end
      end

      def create_reporters(reporters)
        #@human_reporter = reporters[:human].new(error_collection)
        #@hash_reporter = reporters[:hash].new(error_collection)
        #@array_reporter = reporters[:array].new(error_collection)
        @hash_reporter = HashReporter.new(error_collection)
        @human_reporter = HumanReporter.new(error_collection)
      end

      def to_xml(options={})
        to_a.to_xml options.reverse_merge(:root => "errors", :skip_types => true)
      end

      def as_json(options=nil)
        to_hash
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10809906291834002, 'fraction_numerical': 0.0, 'mean_word_length': 2.9959893048128343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4369693', 'n_tokens_mistral': 964, 'n_tokens_neox': 938, 'n_words': 191}