<commit_before>module Dao
  module Repository
    class Base
      class << self
        def entity(entity)
          @entity = entity
        end

        def gateway(gateway = nil, source = nil, transformer = nil)
          if gateway && source && transformer
            @gateway = gateway
            @source = source
            @transformer = transformer
          else
            @gateway.new(@source, @transformer.new(@entity))
          end
        end

        def all
          scope.all.apply
        end

        def find(id, with: nil)
          attributes = {}
          attributes[:with] = with if with
          scope.find(id, attributes).apply
        end

        def find_by_id(id)
          scope.find_by_id(id).apply
        end

        def last(with: nil)
          attributes = {}
          attributes[:with] = with if with
          scope.last(attributes).apply
        end

        def count
          scope.count.apply
        end

        def build(record = nil)
          gateway.map(record, {})
        end

        def save(domain, attributes = {})
          gateway.save!(domain, attributes)
        end

        def save_all(domains)
          with_transaction do
            domains.map { |domain| save(domain) }
          end
        end

        def delete(domain)
          delete_by_id(domain.id) if domain
        end

        def delete_by_id(domain_id)
          gateway.delete(domain_id)
        end

        def with_transaction(&block)
          gateway.with_transaction(&block)
        end

        def by_criteria(criteria)
          criteria.filter(scope).apply
        end

        def by_criteria_count(criteria)
          criteria.count_of_result_items(scope).apply
        end

        protected

        def scope
          Scope.new(gateway)
        end
      end
    end
  end
end<commit_msg>criteria should call apply by himself<commit_after>module Dao
  module Repository
    class Base
      class << self
        def entity(entity)
          @entity = entity
        end

        def gateway(gateway = nil, source = nil, transformer = nil)
          if gateway && source && transformer
            @gateway = gateway
            @source = source
            @transformer = transformer
          else
            @gateway.new(@source, @transformer.new(@entity))
          end
        end

        def all
          scope.all.apply
        end

        def find(id, with: nil)
          attributes = {}
          attributes[:with] = with if with
          scope.find(id, attributes).apply
        end

        def find_by_id(id)
          scope.find_by_id(id).apply
        end

        def last(with: nil)
          attributes = {}
          attributes[:with] = with if with
          scope.last(attributes).apply
        end

        def count
          scope.count.apply
        end

        def build(record = nil)
          gateway.map(record, {})
        end

        def save(domain, attributes = {})
          gateway.save!(domain, attributes)
        end

        def save_all(domains)
          with_transaction do
            domains.map { |domain| save(domain) }
          end
        end

        def delete(domain)
          delete_by_id(domain.id) if domain
        end

        def delete_by_id(domain_id)
          gateway.delete(domain_id)
        end

        def with_transaction(&block)
          gateway.with_transaction(&block)
        end

        def by_criteria(criteria)
          criteria.filter(scope)
        end

        def by_criteria_count(criteria)
          criteria.count_of_result_items(scope)
        end

        protected

        def scope
          Scope.new(gateway)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07389428263214672, 'fraction_numerical': 0.0, 'mean_word_length': 1.4401315789473683, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3681156', 'n_tokens_mistral': 1021, 'n_tokens_neox': 980, 'n_words': 244}