lib/method_log/repository.rb in method_log-0.0.3 vs lib/method_log/repository.rb in method_log-0.0.4
- old
+ new
@@ -2,27 +2,31 @@
require 'method_log/commit'
module MethodLog
class Repository
- attr_reader :commits
-
def initialize(path: nil)
@repository = Rugged::Repository.new(path)
@commits = []
- if @repository.ref('refs/heads/master')
- @repository.walk(@repository.last_commit) do |commit|
- @commits << build_commit(sha: commit.oid)
- end
- end
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
\ No newline at end of file