<commit_before>module Delayed
  module Paperclip
    def self.included(base) #:nodoc:
      base.extend(ClassMethods)
    end

    module ClassMethods
      def process_in_background(name)
        include InstanceMethods

        define_method "#{name}_changed?" do
          attachment_changed?(name)
        end

        define_method "halt_processing_for_#{name}" do
          if self.send("#{name}_changed?")
            false # halts processing
          end
        end

        define_method "enqueue_job_for_#{name}" do
          if self.send("#{name}_changed?")
            if delayed_job?
              Delayed::Job.enqueue DelayedPaperclipJob.new(self.class.name, read_attribute(:id), name.to_sym)
            elsif resque?
              Resque.enqueue(ResquePaperclipJob, self.class.name, read_attribute(:id), name.to_sym)
            end
          end
        end

        define_method "#{name}_requires_processing?" do
          self.new_record? &&
            self.send(:"#{name}_changed?") &&
            self.respond_to?(:"#{name}_processing?")
        end

        define_method "#{name}_processed!" do
          return true unless self.respond_to?(:"#{name}_processing?")
          self.send("#{name}_processing=", false)
          self.save(false)
        end

        define_method "mark_#{name}_as_processing" do
          self.send("#{name}_processing=", true) if self.send("#{name}_requires_processing?")
          true
        end
        private :"mark_#{name}_as_processing"

        self.send("before_#{name}_post_process", :"halt_processing_for_#{name}")

        before_save :"mark_#{name}_as_processing"
        after_save  :"enqueue_job_for_#{name}"
      end
    end

    module InstanceMethods
      PAPERCLIP_ATTRIBUTES = ['_file_size', '_file_name', '_content_type', '_updated_at']<commit_msg>minor change to reduce unneeded saves after processing<commit_after>module Delayed
  module Paperclip
    def self.included(base) #:nodoc:
      base.extend(ClassMethods)
    end

    module ClassMethods
      def process_in_background(name)
        include InstanceMethods

        define_method "#{name}_changed?" do
          attachment_changed?(name)
        end

        define_method "halt_processing_for_#{name}" do
          if self.send("#{name}_changed?")
            false # halts processing
          end
        end

        define_method "enqueue_job_for_#{name}" do
          if self.send("#{name}_changed?")
            if delayed_job?
              Delayed::Job.enqueue DelayedPaperclipJob.new(self.class.name, read_attribute(:id), name.to_sym)
            elsif resque?
              Resque.enqueue(ResquePaperclipJob, self.class.name, read_attribute(:id), name.to_sym)
            end
          end
        end

        define_method "#{name}_requires_processing?" do
          self.new_record? &&
            self.send(:"#{name}_changed?") &&
            self.respond_to?(:"#{name}_processing?")
        end

        define_method "#{name}_processed!" do
          return true unless self.respond_to?(:"#{name}_processing?") &&
                             self.send("#{name}_processing?")
          self.send("#{name}_processing=", false)
          self.save(false)
        end

        define_method "mark_#{name}_as_processing" do
          self.send("#{name}_processing=", true) if self.send("#{name}_requires_processing?")
          true
        end
        private :"mark_#{name}_as_processing"

        self.send("before_#{name}_post_process", :"halt_processing_for_#{name}")

        before_save :"mark_#{name}_as_processing"
        after_save  :"enqueue_job_for_#{name}"
      end
    end

    module InstanceMethods
      PAPERCLIP_ATTRIBUTES = ['_file_size', '_file_name', '_content_type', '_updated_at']
{'fraction_non_alphanumeric': 0.1165693043016463, 'fraction_numerical': 0.0, 'mean_word_length': 2.475092250922509, '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': '1325573', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1104, 'n_words': 195}