Class: Obst::GitLog
- Inherits:
-
Object
- Object
- Obst::GitLog
- Defined in:
- lib/obst/git_log.rb
Defined Under Namespace
Classes: Commit
Constant Summary collapse
- EMPTY_LINE =
"\n"
Instance Method Summary collapse
- #commits ⇒ Object
-
#initialize(**opts) ⇒ GitLog
constructor
A new instance of GitLog.
- #to_s ⇒ Object
Constructor Details
#initialize(**opts) ⇒ GitLog
Returns a new instance of GitLog.
5 6 7 8 9 10 |
# File 'lib/obst/git_log.rb', line 5 def initialize(**opts) path = opts[:C] || '.' @cmd = ['git', '-C', path, 'log', '--name-status', '--pretty=format:%ad', "--date=format:'%Y-%m-%dT%H:%M:%S'"] @cmd << '--after' << opts[:after] if opts[:after] @cmd << '--before' << opts[:before] if opts[:before] end |
Instance Method Details
#commits ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/obst/git_log.rb', line 49 def commits Enumerator.new do |y| batch = [] Open3.popen2(*@cmd) do |stdin, stdout, status_thread| stdout.each_line do |line| next batch << line unless line == EMPTY_LINE y << Commit.new(batch) batch.clear end raise 'fail to loop git log' unless status_thread.value.success? end y << Commit.new(batch) end end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/obst/git_log.rb', line 12 def to_s `#{@cmd.join(' ')}` end |