<commit_before>require 'searchlogic'

module Espresso
  module Model
    def self.included(model)
      model.extend ClassMethods
      model.class_eval do
        include InstanceMethods

        attr_accessor :name_field
        self.name_field = :name
      end
    end

    module ClassMethods
      def paginate_found(page = nil, query = nil, simple_query = nil)
        query ||= {}
        query.merge(parse_simple_query(simple_query)) if simple_query.present?
        @search = search(query)
        @results = @search.paginate(:page => page)
        [@search, @results]
      end

      def parse_simple_query(query)
        {:"#{name_field}_like" => query}
      end

      def name_field(new_name_field = nil)
        if new_name_field.present?
          @@name_field = new_name_field
        end
        @@name_field
      end

      def make_slug(object)
        object.send(name_field).parameterize
      end
    end

    module InstanceMethods
      def to_s
        send(@@name_field).to_s
      end

    protected
    end
  end
end<commit_msg>Added YARD documentation for Espresso::Model<commit_after>require 'searchlogic'

module Espresso
  # @author <NAME>
  module Model
    def self.included(model)
      model.extend ClassMethods
      model.class_eval do
        include InstanceMethods

        attr_accessor :name_field
        self.name_field = :name
      end
    end

    module ClassMethods
      # Paginates search results
      #
      # @param [Integer] page number of results’ page
      # @param [Hash] query searchlogic fields (proc’ed named scopes’ names with values)
      # @param [String] simple_query params for simple «LIKE '%something%'» searches (e.g. /people?q=Alexander)
      # @return [Array] searchlogic object and collection of results
      #
      # @todo Add an options to paginating
      def paginate_found(page = nil, query = nil, simple_query = nil)
        query ||= {}
        query.merge(parse_simple_query(simple_query)) if simple_query.present?
        @search = search(query)
        @results = @search.paginate(:page => page)
        [@search, @results]
      end

      # Make searchlogic query from simple query option
      # Needed to be reimplemented in subclasses
      #
      # @param [String] simple query string
      # @return [Hash] searchlogic query
      def parse_simple_query(query)
        {:"#{name_field}_like" => query}
      end

      # «NameField» is a main field, used to represent model in to_s method and in simple queries
      # @param [Symbol, String] new_name_field new field name
      # @return [Symbol] field name
      def name_field(new_name_field = nil)
        if new_name_field.present?
          @@name_field = new_name_field.to_sym
        end
        @@name_field
      end

      # Make a slug from object’s NameField
      # @param [ActiveRecord::Base] object, which slug is making
      # @return [String] slug
      def make_slug(object)
        object.send(name_field).parameterize
      end
    end

    module InstanceMethods
      def to_s
        send(@@name_field).to_s
      end

    protected
    end
  end
end
{'fraction_non_alphanumeric': 0.08029430582213691, 'fraction_numerical': 0.0, 'mean_word_length': 2.384199134199134, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '3179630', 'n_tokens_mistral': 931, 'n_tokens_neox': 904, 'n_words': 262}