<commit_before>module Setup
  module HashField
    extend ActiveSupport::Concern

    def check_before_save
      errors.blank?
    end

    module ClassMethods

      def hash_field(*field_names)
        field_names = field_names.collect(&:to_s)
        field_names.reject!(&:blank?)

        field_names.each do |field_name|
          field field_name, default: {}
        end

        before_save do
          check_before_save &&
            field_names.each do |field|
              if (metadata = attributes[field]).is_a?(Hash)
                attributes[field] = metadata.to_json<commit_msg>Fixing tracking for hashing fields<commit_after>module Setup
  module HashField
    extend ActiveSupport::Concern

    def check_before_save
      errors.blank?
    end

    module ClassMethods

      def hash_field(*field_names)
        field_names = field_names.collect(&:to_s)
        field_names.reject!(&:blank?)

        field_names.each do |field_name|
          field field_name, default: {}
        end

        before_save do
          check_before_save &&
            field_names.each do |field|
              if (value = attributes[field]).is_a?(Hash)
                attributes[field] = value = value.to_json
              end
              if (changed_value = changed_attributes[field]) &&
                (changed_value.is_a?(String) || (changed_value = changed_value.to_json)) &&
                value == changed_value
                changed_attributes.delete(field)
{'fraction_non_alphanumeric': 0.08305199189736664, 'fraction_numerical': 0.0, 'mean_word_length': 2.1666666666666665, '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': '2950150', 'n_tokens_mistral': 417, 'n_tokens_neox': 402, 'n_words': 84}