<commit_before>module FatJam
  module ActsAsRevisable
    module Revisable
      def self.included(base)
        base.send(:extend, ClassMethods)
                
        class << base
          alias_method_chain :find, :revisable
          alias_method_chain :with_scope, :revisable
          attr_accessor :revisable_revision_class, :revisable_columns
        end
        
        base.instance_eval do
          attr_accessor :revisable_no_revision, :revisable_new_params, :revisable_force_revision, :revisable_revision
          
          define_callbacks :before_revise, :after_revise, :before_revert, :after_revert, :before_changeset, :after_changeset, :after_branch_created
          
          alias_method_chain :save, :revisable
          alias_method_chain :save!, :revisable
          
          before_create :before_revisable_create
          before_update :before_revisable_update
          after_update :after_revisable_update
          
          acts_as_scoped_model :find => {:conditions => {:revisable_is_current => true}}
          
          [:revisions, revisions_association_name.to_sym].each do |assoc|
            has_many assoc, (revisable_options.revision_association_options || {}).merge({:class_name => revision_class_name, :foreign_key => :revisable_original_id, :order => "#{quoted_table_name}.#{connection.quote_column_name(:revisable_number)} DESC", :dependent => :destroy})
          end
        end
      end
      
      # Find a +Revision+ by revision_number.
      def find_revision(by)
        case by
        when self.class.revision_class
          by
        when :first
          revisions.last
        when :previous
          revisions.first
        when Time
          revisions.find(:first, :conditions => ["? >= ? and ? <= ?", :revisable_revised_at, by, :revisable_current_at, by])
        else
          revisions.find_by_revisable_number(by)<commit_msg>AAR returns 0 as the revision_number for yet-to-be revised records, so make find_revision work with it.<commit_after>module FatJam
  module ActsAsRevisable
    module Revisable
      def self.included(base)
        base.send(:extend, ClassMethods)
                
        class << base
          alias_method_chain :find, :revisable
          alias_method_chain :with_scope, :revisable
          attr_accessor :revisable_revision_class, :revisable_columns
        end
        
        base.instance_eval do
          attr_accessor :revisable_no_revision, :revisable_new_params, :revisable_force_revision, :revisable_revision
          
          define_callbacks :before_revise, :after_revise, :before_revert, :after_revert, :before_changeset, :after_changeset, :after_branch_created
          
          alias_method_chain :save, :revisable
          alias_method_chain :save!, :revisable
          
          before_create :before_revisable_create
          before_update :before_revisable_update
          after_update :after_revisable_update
          
          acts_as_scoped_model :find => {:conditions => {:revisable_is_current => true}}
          
          [:revisions, revisions_association_name.to_sym].each do |assoc|
            has_many assoc, (revisable_options.revision_association_options || {}).merge({:class_name => revision_class_name, :foreign_key => :revisable_original_id, :order => "#{quoted_table_name}.#{connection.quote_column_name(:revisable_number)} DESC", :dependent => :destroy})
          end
        end
      end
      
      # Find a +Revision+ by revision_number.
      def find_revision(by)
        case by
        when self.class.revision_class
          by
        when :first
          revisions.last
        when :previous
          revisions.first
        when Time
          revisions.find(:first, :conditions => ["? >= ? and ? <= ?", :revisable_revised_at, by, :revisable_current_at, by])
        when 0
          self
        else
          revisions.find_by_revisable_number(by)
{'fraction_non_alphanumeric': 0.08138351983723296, 'fraction_numerical': 0.000508646998982706, 'mean_word_length': 2.5625, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '6946137', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1162, 'n_words': 221}