<commit_before>module ModelsWatcher

  def self.included(base)
    base.send(:extend, ClassMethods)
    base.send(:include, InstanceMethods)
    base.class_eval do
      before_save :check_watched_fields
    end
  end

  module ClassMethods

    def watch_fields(*fields)
      define_method :check_watched_fields do
        fields.each do |field|
          if self.send "#{field}_changed?"
            update_changes_to_apply
          end
        end
      end
    end

    def watch_on_destroy
      after_destroy :update_changes_to_apply
    end

  end

  module InstanceMethods
    def update_changes_to_apply
      Configuration.first.update_attribute(:changes_to_apply, true)
    end
  end

end<commit_msg>Modified ModelsWatcher so it can call watch_fields several times<commit_after>module ModelsWatcher

  def self.included(base)
    base.send(:extend, ClassMethods)
    base.send(:include, InstanceMethods)
    base.class_eval do
      @__watched_fields ||= []
      before_save :check_watched_fields
    end
  end

  module ClassMethods

    def watch_fields(*fields)
      @__watched_fields += fields
    end

    def watch_on_destroy
      after_destroy :update_changes_to_apply
    end

  end

  module InstanceMethods

    def check_watched_fields
      fields = self.class.instance_eval do @__watched_fields end
      fields.each do |field|
        if self.send "#{field}_changed?"
          update_changes_to_apply
          break
        end
      end
    end

    def update_changes_to_apply
      Configuration.first.update_attribute(:changes_to_apply, true)
    end
  end

end
{'fraction_non_alphanumeric': 0.056355666875391355, 'fraction_numerical': 0.0, 'mean_word_length': 2.795724465558195, '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': '2932857', 'n_tokens_mistral': 485, 'n_tokens_neox': 469, 'n_words': 109}