Class: Git::Log::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/git/log.rb

Overview

An immutable collection of commits returned by Git::Log#execute

This object is an Enumerable that contains Git::Object::Commit objects. It provides methods to access the commit data without executing any further git commands.

Instance Method Summary collapse

Constructor Details

#initialize(commits) ⇒ Result

Returns a new instance of Result.



41
42
43
# File 'lib/git/log.rb', line 41

def initialize(commits)
  @commits = commits
end

Instance Method Details

#[](index) ⇒ Git::Object::Commit?

Returns the commit at the given index.

Parameters:

  • index (Integer)

    the index of the commit to return

Returns:



69
70
71
# File 'lib/git/log.rb', line 69

def [](index)
  @commits[index]
end

#each {|Git::Object::Commit| ... }

Iterates over each commit in the result set



53
54
55
# File 'lib/git/log.rb', line 53

def each(&block)
  @commits.each(&block)
end

#firstGit::Object::Commit?

Returns the first commit in the result set.

Returns:



58
59
60
# File 'lib/git/log.rb', line 58

def first
  @commits.first
end

#lastGit::Object::Commit?

Returns the last commit in the result set.

Returns:



63
64
65
# File 'lib/git/log.rb', line 63

def last
  @commits.last
end

#sizeInteger

Returns the number of commits in the result set.

Returns:

  • (Integer)

    the number of commits in the result set



46
47
48
# File 'lib/git/log.rb', line 46

def size
  @commits.size
end

#to_sString

Returns a string representation of the log.

Returns:

  • (String)

    a string representation of the log



74
75
76
# File 'lib/git/log.rb', line 74

def to_s
  map { |c| c.to_s }.join("\n")
end