<commit_before>module CanCan
  module ModelAdapters
    class DataMapperAdapter < AbstractAdapter
      def self.for_class?(model_class)
        model_class <= DataMapper::Resource
      end

      def self.find(model_class, id)
        model_class.get(id)
      end

      def self.override_conditions_hash_matching?(subject, conditions)
        conditions.any? { |k,v| !k.kind_of?(Symbol) }
      end

      def self.matches_conditions_hash?(subject, conditions)
        collection = DataMapper::Collection.new(subject.query, [ subject ])
        !!collection.first(conditions)
      end

      def database_records
        scope = @model_class.all(:conditions => ["0 = 1"])
        cans, cannots = @rules.partition { |r| r.base_behavior }
        return scope if cans.empty?
        # apply unions first, then differences. this mean cannot overrides can
        cans.each    { |r| scope += @model_class.all(:conditions => r.conditions) }
        cannots.each { |r| scope -= @model_class.all(:conditions => r.conditions) }
        scope
      end
    end # class DataMapper
  end # module ModelAdapters
end # module CanCan

DataMapper::Model.class_eval do
  include CanCan::ModelAdditions::ClassMethods
end
<commit_msg>Load datamapper class methods via append_extensions.<commit_after>module CanCan
  module ModelAdapters
    class DataMapperAdapter < AbstractAdapter
      def self.for_class?(model_class)
        model_class <= DataMapper::Resource
      end

      def self.find(model_class, id)
        model_class.get(id)
      end

      def self.override_conditions_hash_matching?(subject, conditions)
        conditions.any? { |k,v| !k.kind_of?(Symbol) }
      end

      def self.matches_conditions_hash?(subject, conditions)
        collection = DataMapper::Collection.new(subject.query, [ subject ])
        !!collection.first(conditions)
      end

      def database_records
        scope = @model_class.all(:conditions => ["0 = 1"])
        cans, cannots = @rules.partition { |r| r.base_behavior }
        return scope if cans.empty?
        # apply unions first, then differences. this mean cannot overrides can
        cans.each    { |r| scope += @model_class.all(:conditions => r.conditions) }
        cannots.each { |r| scope -= @model_class.all(:conditions => r.conditions) }
        scope
      end
    end # class DataMapper
  end # module ModelAdapters
end # module CanCan

DataMapper::Model.append_extensions(CanCan::ModelAdditions::ClassMethods)

{'fraction_non_alphanumeric': 0.10072815533980582, 'fraction_numerical': 0.0016181229773462784, 'mean_word_length': 2.995153473344103, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7550934', 'n_tokens_mistral': 715, 'n_tokens_neox': 697, 'n_words': 169}