Sha256: 9a43a7ec65ef2b1e5f7d02043ab480ae0478100e2f4bc62b1fd0407a9dc42850

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

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)
      Enumerator.new do |yielder|
        @repository.commits.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)
        end
      end
    end

    def diffs(method_identifier)
      Enumerator.new do |yielder|
        history(method_identifier).each_cons(2) do |(commit, parent)|
          diff = MethodDiff.new(commit: commit, parent: parent)
          unless diff.empty?
            yielder << [commit, diff]
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
method_log-0.0.3 lib/method_log/api.rb