Class: Obst::PackLog

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/obst/pack_log.rb

Defined Under Namespace

Classes: Changes, Record

Instance Method Summary collapse

Constructor Details

#initialize(**opts, &block) ⇒ PackLog

Returns a new instance of PackLog.



7
8
9
10
# File 'lib/obst/pack_log.rb', line 7

def initialize(**opts, &block)
  @commits = GitLog.new(**opts).commits
  @time_fix = block
end

Instance Method Details

#each(&block) ⇒ Object

yield PackLog::Record(

time:Any,
file_changes:Hash{
  name1 => [:m, :a],
  name2 => [:d, :m],
  ...
}

)



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/obst/pack_log.rb', line 81

def each(&block)
  return self unless block

  current_time = nil
  renames = {}
  files_in_one_day = Hash.new{ |files, name| files[name] = Changes.new }

  @commits.each do |commit|
    committed_at = @time_fix.call(commit.committed_at)
    current_time ||= committed_at

    if current_time != committed_at
      block.call(Record.new(current_time, files_in_one_day.dup))
      current_time = committed_at
      files_in_one_day.clear
    end

    commit.file_statuses.each do |file_status|
      renames[file_status.old_name] = file_status.name if file_status.old_name
      newest_name = renames[file_status.name] || file_status.name
      files_in_one_day[newest_name] << file_status.status
    end
  end

  block.call(Record.new(current_time, files_in_one_day.dup))
end