Sha256: 666315292db0669130153d9a2c943d8c2a7f084f528069fa3a464e018544fa20

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

require 'method_log/method_finder'
require 'method_log/method_commit'
require 'method_log/method_diff'

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

    def history(method_identifier, options = {})
      options = { stop_at_latest_introduction_of_method: true }.merge(options)
      Enumerator.new do |yielder|
        last_method_commit = nil
        @repository.commits(options).each do |commit|
          last_source_file = last_method_commit && last_method_commit.source_file
          if last_source_file && commit.contains?(last_source_file)
            last_method_commit.update(commit)
          else
            method_definition = commit.find(method_identifier, last_source_file)
            yielder << last_method_commit if last_method_commit
            last_method_commit = MethodCommit.new(commit, method_definition)
            yielder << last_method_commit
            break if options[:stop_at_latest_introduction_of_method] && method_definition.nil?
          end
        end
      end
    end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
method_log-0.2.1 lib/method_log/api.rb
method_log-0.2.0 lib/method_log/api.rb
method_log-0.1.1 lib/method_log/api.rb
method_log-0.1.0 lib/method_log/api.rb