<commit_before>module Pod

  # Manages all the sources known to the running CocoaPods Instance.
  #
  class SourcesManager

    class << self

      include Config::Mixin

      # @return [Source::Aggregate] the aggregate of all the sources known to
      #         this installation of CocoaPods.
      #
      def aggregate
        Source::Aggregate.new(config.repos_dir)
      end

      # @return [Array<Source>] the list of all the sources known to this
      #         installation of CocoaPods.
      #
      def all
        aggregate.all
      end

      # @return [Array<Specification::Set>] the list of all the specification
      #         sets know to this installation of CocoaPods.
      #
      def all_sets
        aggregate.all_sets
      end

      # Search all the sources to match the set for the given dependency.
      #
      # @return [Set, nil] a set for a given dependency including all the
      #         {Source} that contain the Pod. If no sources containing the
      #         Pod where found it returns nil.
      #
      # @raise  If no source including the set can be found.
      #
      def search(dependency)
        aggregate.search(dependency)
      end

      # Search all the sources with the given search term.
      #
      # @param  [String] query
      #         The search term.
      #
      # @param  [Bool] full_text_search
      #         Whether the search should be limited to the name of the Pod or
      #         should include also the author, the summary, and the
      #         description.
      #
      # @raise  If no source including the set can be found.
      #
      # @note   Full text search requires to load the specification for each
      #         pod, hence is considerably slower.
      #
      # @return [Array<Set>]  The sets that contain the search term.
      #
      def search_by_name(query, full_text_search = false)
        if full_text_search
          set_names = []
          query_regexp = %r{#{query}}i
          updated_search_index.each do |name, set_data|
            texts = [name]
            if full_text_search
              texts << set_data['authors'].to_s if set_data['authors']
              texts << set_data['summary']      if set_data['summary']
              texts << set_data['description']  if set_data['description']
            end
            set_names << name unless texts.grep(query_regexp).empty?
          end
          sets = set_names.sort.map { |name| aggregate.represenative_set(name) }
        else
          sets = aggregate.search_by_name(query, false)
        end
        if sets.empty?
          extra = ", author, summary, or description" if full_text_search
          raise Informative, "Unable to find a pod with name#{extra} matching `#{query}`"
        end
        sets
      end

      # Creates or updates the search data and returns it. The search data
      # groups by name the following information for each set:
      #
      #   - version
      #   - summary
      #   - description
      #   - authors
      #
      # @note   This operation is fairly expensive, because of the YAML
      #         conversion.
      #<commit_msg>Use the same style as in Core for creating the regular expression query.<commit_after>module Pod

  # Manages all the sources known to the running CocoaPods Instance.
  #
  class SourcesManager

    class << self

      include Config::Mixin

      # @return [Source::Aggregate] the aggregate of all the sources known to
      #         this installation of CocoaPods.
      #
      def aggregate
        Source::Aggregate.new(config.repos_dir)
      end

      # @return [Array<Source>] the list of all the sources known to this
      #         installation of CocoaPods.
      #
      def all
        aggregate.all
      end

      # @return [Array<Specification::Set>] the list of all the specification
      #         sets know to this installation of CocoaPods.
      #
      def all_sets
        aggregate.all_sets
      end

      # Search all the sources to match the set for the given dependency.
      #
      # @return [Set, nil] a set for a given dependency including all the
      #         {Source} that contain the Pod. If no sources containing the
      #         Pod where found it returns nil.
      #
      # @raise  If no source including the set can be found.
      #
      def search(dependency)
        aggregate.search(dependency)
      end

      # Search all the sources with the given search term.
      #
      # @param  [String] query
      #         The search term.
      #
      # @param  [Bool] full_text_search
      #         Whether the search should be limited to the name of the Pod or
      #         should include also the author, the summary, and the
      #         description.
      #
      # @raise  If no source including the set can be found.
      #
      # @note   Full text search requires to load the specification for each
      #         pod, hence is considerably slower.
      #
      # @return [Array<Set>]  The sets that contain the search term.
      #
      def search_by_name(query, full_text_search = false)
        if full_text_search
          set_names = []
          query_regexp = /#{query}/i
          updated_search_index.each do |name, set_data|
            texts = [name]
            if full_text_search
              texts << set_data['authors'].to_s if set_data['authors']
              texts << set_data['summary']      if set_data['summary']
              texts << set_data['description']  if set_data['description']
            end
            set_names << name unless texts.grep(query_regexp).empty?
          end
          sets = set_names.sort.map { |name| aggregate.represenative_set(name) }
        else
          sets = aggregate.search_by_name(query, false)
        end
        if sets.empty?
          extra = ", author, summary, or description" if full_text_search
          raise Informative, "Unable to find a pod with name#{extra} matching `#{query}`"
        end
        sets
      end

      # Creates or updates the search data and returns it. The search data
      # groups by name the following information for each set:
      #
      #   - version
      #   - summary
      #   - description
      #   - authors
      #
      # @note   This operation is fairly expensive, because of the YAML
      #         conversion.
      #
{'fraction_non_alphanumeric': 0.06985121378230227, 'fraction_numerical': 0.0, 'mean_word_length': 1.8256637168141594, 'pattern_counts': {'":': 0, '<': 29, '<?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': '6517931', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1690, 'n_words': 624}