<commit_before>require 'method_log/method_finder'
require 'method_log/method_commit'
require 'method_log/method_diff'

module MethodLog
  class API
    def initialize(repository: nil)
      @repository = repository
    end

    def history(method_identifier, max_count: nil)
      Enumerator.new do |yielder|
        @repository.commits(max_count: max_count).each do |commit|
          method_definitions = commit.source_files.inject([]) do |definitions, source_file|
            method_finder = MethodFinder.new(source_file: source_file)
            definitions += Array(method_finder.find(method_identifier))
          end
          yielder << MethodCommit.new(commit: commit, method_definition: method_definitions.first)<commit_msg>Only parse source files containing method name.<commit_after>require 'method_log/method_finder'
require 'method_log/method_commit'
require 'method_log/method_diff'

module MethodLog
  class API
    def initialize(repository: nil)
      @repository = repository
    end

    def history(method_identifier, max_count: nil)
      method_name = method_identifier.split(Regexp.union('#', '.')).last
      Enumerator.new do |yielder|
        @repository.commits(max_count: max_count).each do |commit|
          source_files = commit.source_files.select { |sf| sf.source[Regexp.new(method_name)] }
          method_definitions = source_files.inject([]) do |definitions, source_file|
            method_finder = MethodFinder.new(source_file: source_file)
            definitions += Array(method_finder.find(method_identifier))
          end
          yielder << MethodCommit.new(commit: commit, method_definition: method_definitions.first)
{'fraction_non_alphanumeric': 0.09243697478991597, 'fraction_numerical': 0.0, 'mean_word_length': 3.902941176470588, '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': '4586874', 'n_tokens_mistral': 469, 'n_tokens_neox': 468, 'n_words': 98}