Class: DeltaTest::CLI::StatsSaveCommand

Inherits:
CommandBase show all
Defined in:
lib/delta_test/cli/stats_save_command.rb

Constant Summary

Constants inherited from CommandBase

CommandBase::DEFAULT_OPTIONS

Instance Method Summary collapse

Methods inherited from CommandBase

#bundler_enabled?, #exec_with_data, #exit_with_message, #initialize, #invoke, #parse_options!

Constructor Details

This class inherits a constructor from DeltaTest::CLI::CommandBase

Instance Method Details

#cleanup_tmp_table_filesObject

[View source]

27
28
29
30
# File 'lib/delta_test/cli/stats_save_command.rb', line 27

def cleanup_tmp_table_files
  tmp_dir = DeltaTest.config.tmp_table_file.parent
  FileUtils.rm_rf(tmp_dir) if File.directory?(tmp_dir)
end

#invoke!Object

[View source]

11
12
13
14
15
16
17
18
# File 'lib/delta_test/cli/stats_save_command.rb', line 11

def invoke!
  load_tmp_table_files
  cleanup_tmp_table_files
  save_table_file

  stage_table_file
  sync_table_file unless @options['no-sync']
end

#load_tmp_table_filesObject

[View source]

20
21
22
23
24
25
# File 'lib/delta_test/cli/stats_save_command.rb', line 20

def load_tmp_table_files
  tmp_table_files.each do |tmp_table_file|
    tmp_table = DependenciesTable.load(tmp_table_file)
    table.reverse_merge!(tmp_table)
  end
end

#save_table_fileObject

[View source]

32
33
34
# File 'lib/delta_test/cli/stats_save_command.rb', line 32

def save_table_file
  table.dump(stats.table_file_path)
end

#stage_table_fileObject

[View source]

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

def stage_table_file
  status = true
  status &&= stats.stats_git.add(stats.table_file_path)
  status &&= stats.stats_git.commit(stats.base_commit)
  raise TableFileStageError unless status
end

#statsObject

[View source]

61
62
63
# File 'lib/delta_test/cli/stats_save_command.rb', line 61

def stats
  @stats ||= Stats.new(head: true)
end

#sync_table_fileObject

[View source]

43
44
45
46
47
48
49
# File 'lib/delta_test/cli/stats_save_command.rb', line 43

def sync_table_file
  return unless stats.stats_git.has_remote?
  status = true
  status &&= stats.stats_git.pull
  status &&= stats.stats_git.push
  raise StatsRepositorySyncError unless status
end

#tableObject

[View source]

57
58
59
# File 'lib/delta_test/cli/stats_save_command.rb', line 57

def table
  @table ||= DependenciesTable.new
end

#tmp_table_filesObject

[View source]

51
52
53
54
55
# File 'lib/delta_test/cli/stats_save_command.rb', line 51

def tmp_table_files
  return @tmp_table_files if defined?(@tmp_table_files)
  tmp_table_files_pattern ||= DeltaTest.config.tmp_table_file.parent.join('*')
  @tmp_table_files = Dir.glob(tmp_table_files_pattern)
end