<commit_before>module DataMapper
  module Support
    
    module ActiveRecordImpersonation
      
      def self.included(base)
        base.extend(ClassMethods)
      end
      
      def save
        database_context.save(self)
      end
      
      def save!
        raise ValidationError.new(errors) unless save
        return true
      end
      
      def reload!(cols = nil)
        database_context.first(self.class, key, :select => cols || original_values.keys, :reload => true)
        self.loaded_associations.each { |association| association.reload! }
        self
      end
      alias reload reload!
      
      def destroy!
        database_context.destroy(self)
      end
      
      module ClassMethods
        
        def find_or_create(search_attributes, create_attributes = {})
          first(search_attributes) || create(search_attributes.merge(create_attributes))
        end
        
        def all(options = {})
          database.all(self, options)
        end
        
        def each(options = {}, &b)
          raise ArgumentError.new(":offset is not supported with the #each method") if options.has_key?(:offset)

          offset = 0
          limit = options[:limit] || (self::const_defined?('DEFAULT_LIMIT') ? self::DEFAULT_LIMIT : 500)

          until (results = all(options.merge(:limit => limit, :offset => offset))).empty?
            results.each(&b)
            offset += limit
          end
        end
        
        def first(*args)
          database.first(self, *args)
        end
        
        def count(*args)
          database.count(self, *args)
        end
        
        def delete_all
          database.delete_all(self)
        end
        
        def truncate!
          database.truncate(self)
        end
        
        def find(type_or_id, options = {})
          case type_or_id
            when :first then first(options)
            when :all then all(options)
            else first(type_or_id, options)
          end
        end
        
        def find_by_sql(*args)
          DataMapper::database.query(*args)
        end
        
        def get(*keys)
          database.get(self, keys)
        end
        
        def [](*keys)
          # Eventually this ArgumentError should be removed. It's only here to help
          # migrate users away from the [options_hash] syntax, which is no longer supported.
          raise ArgumentError.new('Hash is not a valid key') if keys.size == 1 && keys.first.is_a?(Hash)
          instance = database.get(self, keys)
          raise ObjectNotFoundError.new() unless instance
          return instance
        end
        
        def create(attributes)
          instance = self.new
          instance.attributes = attributes
          instance.save
          instance
        end
        
        def create!(attributes)
          instance = self.new
          instance.attributes = attributes
          instance.save
          raise ObjectNotFoundError.new(instance) if instance.new_record?
          instance
        end
      end
    end
    
  end
end
<commit_msg>Fix stupid error I intro'ed<commit_after>module DataMapper
  module Support
    
    module ActiveRecordImpersonation
      
      def self.included(base)
        base.extend(ClassMethods)
      end
      
      def save
        database_context.save(self)
      end
      
      def save!
        raise ValidationError.new(errors) unless save
        return true
      end
      
      def reload!(cols = nil)
        database_context.first(self.class, key, :select => ([self.class.table.key.to_sym] + (cols || original_values.keys)).uniq, :reload => true)
        self.loaded_associations.each { |association| association.reload! }
        self
      end
      alias reload reload!
      
      def destroy!
        database_context.destroy(self)
      end
      
      module ClassMethods
        
        def find_or_create(search_attributes, create_attributes = {})
          first(search_attributes) || create(search_attributes.merge(create_attributes))
        end
        
        def all(options = {})
          database.all(self, options)
        end
        
        def each(options = {}, &b)
          raise ArgumentError.new(":offset is not supported with the #each method") if options.has_key?(:offset)

          offset = 0
          limit = options[:limit] || (self::const_defined?('DEFAULT_LIMIT') ? self::DEFAULT_LIMIT : 500)

          until (results = all(options.merge(:limit => limit, :offset => offset))).empty?
            results.each(&b)
            offset += limit
          end
        end
        
        def first(*args)
          database.first(self, *args)
        end
        
        def count(*args)
          database.count(self, *args)
        end
        
        def delete_all
          database.delete_all(self)
        end
        
        def truncate!
          database.truncate(self)
        end
        
        def find(type_or_id, options = {})
          case type_or_id
            when :first then first(options)
            when :all then all(options)
            else first(type_or_id, options)
          end
        end
        
        def find_by_sql(*args)
          DataMapper::database.query(*args)
        end
        
        def get(*keys)
          database.get(self, keys)
        end
        
        def [](*keys)
          # Eventually this ArgumentError should be removed. It's only here to help
          # migrate users away from the [options_hash] syntax, which is no longer supported.
          raise ArgumentError.new('Hash is not a valid key') if keys.size == 1 && keys.first.is_a?(Hash)
          instance = database.get(self, keys)
          raise ObjectNotFoundError.new() unless instance
          return instance
        end
        
        def create(attributes)
          instance = self.new
          instance.attributes = attributes
          instance.save
          instance
        end
        
        def create!(attributes)
          instance = self.new
          instance.attributes = attributes
          instance.save
          raise ObjectNotFoundError.new(instance) if instance.new_record?
          instance
        end
      end
    end
    
  end
end

{'fraction_non_alphanumeric': 0.08054443554843875, 'fraction_numerical': 0.0016012810248198558, 'mean_word_length': 1.6488549618320612, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '1885017', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1613, 'n_words': 419}