Class: DeltaTest::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/delta_test/stats.rb

Constant Summary collapse

TABLE_FILENAME_TPL =
'%s.table'.freeze
TABLE_FILENAME_PATTERN =
'*.table'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(head: false) ⇒ Stats

Returns a new instance of Stats.



12
13
14
15
16
17
# File 'lib/delta_test/stats.rb', line 12

def initialize(head: false)
  @head = !!head

  @base_git  = Git.new(DeltaTest.config.base_path)
  @stats_git = Git.new(DeltaTest.config.stats_path)
end

Instance Attribute Details

#base_gitObject (readonly)

Returns the value of attribute base_git.



6
7
8
# File 'lib/delta_test/stats.rb', line 6

def base_git
  @base_git
end

#stats_gitObject (readonly)

Returns the value of attribute stats_git.



7
8
9
# File 'lib/delta_test/stats.rb', line 7

def stats_git
  @stats_git
end

Instance Method Details

#base_commitObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/delta_test/stats.rb', line 19

def base_commit
  return @base_commit if defined?(@base_commit)

  if @head
    @base_commit = @base_git.rev_parse('HEAD')
  else
    indexes = @stats_git.ls_files
      .map { |f| f.split('/').take(2).join('') }
      .to_set

    @base_commit = @base_git.ls_hashes(DeltaTest.config.stats_life)
      .find { |h| indexes.include?(h) }
  end

  @base_commit
end

#commit_dirObject



36
37
38
39
40
41
# File 'lib/delta_test/stats.rb', line 36

def commit_dir
  return unless base_commit
  return @commit_dir if defined?(@commit_dir)

  @commit_dir = DeltaTest.config.stats_path.join(*base_commit.unpack('A2A*'))
end

#table_file_pathObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/delta_test/stats.rb', line 43

def table_file_path
  return unless commit_dir
  return @table_file_path if defined?(@table_file_path)

  if @head
    @table_file_path = commit_dir.join(TABLE_FILENAME_TPL % [DeltaTest.tester_id])
  else
    file = Dir.glob(commit_dir.join(TABLE_FILENAME_PATTERN)).max do |f|
      File.basename(f).split('-').take(2).join('.').to_f
    end
    @table_file_path = file
    @table_file_path = Pathname.new(file) if file
  end

  @table_file_path
end