Class: Git::Log
Overview
Builds and executes a git log query.
This class provides a fluent interface for building complex git log queries.
The query is lazily executed when results are requested either via the modern
#execute method or the deprecated Enumerable methods.
Constant Summary collapse
- Result =
An immutable, Enumerable collection of
Git::Object::Commitobjects. Returned byGit::Log#execute. Data.define(:commits) do include Enumerable def each(&block) = commits.each(&block) def last = commits.last def [](index) = commits[index] def to_s = map(&:to_s).join("\n") def size = commits.size end
Deprecated Enumerable Interface collapse
-
#each
deprecated
Deprecated.
Use #execute and call
eachon the result. -
#size
deprecated
Deprecated.
Use #execute and call
sizeon the result. -
#to_s
deprecated
Deprecated.
Use #execute and call
to_son the result.
Instance Method Summary collapse
- #all
- #author(regex)
- #between(val1, val2 = nil)
- #cherry
-
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object.
- #grep(regex)
-
#initialize(base, max_count = 30) ⇒ Log
constructor
Create a new Git::Log object.
-
#max_count(num)
Set query options using a fluent interface.
- #merges
- #object(objectish)
- #path(path)
- #since(date)
- #skip(num)
- #until(date)
Constructor Details
#initialize(base, max_count = 30) ⇒ Log
Create a new Git::Log object
46 47 48 49 50 51 |
# File 'lib/git/log.rb', line 46 def initialize(base, max_count = 30) @base = base @options = {} @dirty = true self.max_count(max_count) end |
Instance Method Details
#all
57 |
# File 'lib/git/log.rb', line 57 def all = set_option(:all, true) |
#author(regex)
59 |
# File 'lib/git/log.rb', line 59 def (regex) = set_option(:author, regex) |
#between(val1, val2 = nil)
65 |
# File 'lib/git/log.rb', line 65 def between(val1, val2 = nil) = set_option(:between, [val1, val2]) |
#cherry
66 |
# File 'lib/git/log.rb', line 66 def cherry = set_option(:cherry, true) |
#each
Use #execute and call each on the result.
92 93 94 95 |
# File 'lib/git/log.rb', line 92 def each(&) deprecate_and_run @commits.each(&) end |
#execute ⇒ Git::Log::Result
Executes the git log command and returns an immutable result object
This is the preferred way to get log data. It separates the query building from the execution, making the API more predictable.
84 85 86 87 |
# File 'lib/git/log.rb', line 84 def execute run_log_if_dirty Result.new(@commits) end |
#grep(regex)
60 |
# File 'lib/git/log.rb', line 60 def grep(regex) = set_option(:grep, regex) |
#max_count(num)
Set query options using a fluent interface.
Each method returns self to allow for chaining.
56 |
# File 'lib/git/log.rb', line 56 def max_count(num) = set_option(:count, num == :all ? nil : num) |
#merges
67 |
# File 'lib/git/log.rb', line 67 def merges = set_option(:merges, true) |
#object(objectish)
58 |
# File 'lib/git/log.rb', line 58 def object(objectish) = set_option(:object, objectish) |
#path(path)
61 |
# File 'lib/git/log.rb', line 61 def path(path) = set_option(:path_limiter, path) |
#since(date)
63 |
# File 'lib/git/log.rb', line 63 def since(date) = set_option(:since, date) |
#size
Use #execute and call size on the result.
98 99 100 101 |
# File 'lib/git/log.rb', line 98 def size deprecate_and_run @commits&.size end |
#skip(num)
62 |
# File 'lib/git/log.rb', line 62 def skip(num) = set_option(:skip, num) |
#to_s
Use #execute and call to_s on the result.
104 105 106 107 |
# File 'lib/git/log.rb', line 104 def to_s deprecate_and_run @commits&.map(&:to_s)&.join("\n") end |
#until(date)
64 |
# File 'lib/git/log.rb', line 64 def until(date) = set_option(:until, date) |