Class: TestBoosters::Files::Distributor

Inherits:
Object
  • Object
show all
Defined in:
lib/test_boosters/files/distributor.rb

Overview

Distributes test files based on split configuration, file pattern, and their file size

Instance Method Summary collapse

Constructor Details

#initialize(split_configuration_path, file_pattern, exclude_pattern, job_count) ⇒ Distributor

Returns a new instance of Distributor.



9
10
11
12
13
14
# File 'lib/test_boosters/files/distributor.rb', line 9

def initialize(split_configuration_path, file_pattern, exclude_pattern, job_count)
  @split_configuration_path = split_configuration_path
  @file_pattern = file_pattern
  @exclude_pattern = exclude_pattern
  @job_count = job_count
end

Instance Method Details

#all_filesObject



29
30
31
32
33
34
35
# File 'lib/test_boosters/files/distributor.rb', line 29

def all_files
  @all_files ||= begin
    files = Dir[@file_pattern].sort
    files -= Dir[@exclude_pattern] if @exclude_pattern
    files
  end
end

#display_infoObject



16
17
18
19
20
# File 'lib/test_boosters/files/distributor.rb', line 16

def display_info
  puts "Split configuration present: #{split_configuration.present? ? "yes" : "no"}"
  puts "Split configuration valid: #{split_configuration.valid? ? "yes" : "no"}"
  puts "Split configuration file count: #{split_configuration.all_files.size}"
end

#files_for(job_index) ⇒ Object



22
23
24
25
26
27
# File 'lib/test_boosters/files/distributor.rb', line 22

def files_for(job_index)
  known    = all_files & split_configuration.files_for_job(job_index)
  leftover = leftover_files.select(:index => job_index, :total => @job_count)

  [known, leftover]
end