Sha256: 48476ae006f50ad0ebadfb4c59a4be78e678e76ffebc3d1f91200fb6becfbc6f

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

require 'rugged'

require 'method_log/commit'

module MethodLog
  class Repository
    def initialize(path: nil)
      @repository = Rugged::Repository.new(path)
      @commits = []
    end

    def build_commit(sha: nil)
      Commit.new(repository: @repository, sha: sha)
    end

    def add(commit)
      commit.apply
      @commits << commit
    end

    def commits(max_count: nil)
      Enumerator.new do |yielder|
        if @repository.ref('refs/heads/master')
          @repository.walk(@repository.last_commit).with_index do |commit, index|
            break if max_count && index >= max_count - 1
            yielder << build_commit(sha: commit.oid)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
method_log-0.0.5 lib/method_log/repository.rb
method_log-0.0.4 lib/method_log/repository.rb