Class: Knapsack::Distributors::BaseDistributor

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack/distributors/base_distributor.rb

Direct Known Subclasses

LeftoverDistributor, ReportDistributor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ BaseDistributor

Returns a new instance of BaseDistributor.



6
7
8
9
10
11
12
13
14
15
# File 'lib/knapsack/distributors/base_distributor.rb', line 6

def initialize(args={})
  @report = args[:report] || raise('Missing report')
  @test_file_pattern = args[:test_file_pattern] || raise('Missing test_file_pattern')
  @ci_node_total = args[:ci_node_total] || raise('Missing ci_node_total')
  @ci_node_index = args[:ci_node_index] || raise('Missing ci_node_index')

  if ci_node_index >= ci_node_total
    raise("Node indexes are 0-based. Can't be higher or equal to the total number of nodes.")
  end
end

Instance Attribute Details

#node_testsObject (readonly)

Returns the value of attribute node_tests.



4
5
6
# File 'lib/knapsack/distributors/base_distributor.rb', line 4

def node_tests
  @node_tests
end

#reportObject (readonly)

Returns the value of attribute report.



4
5
6
# File 'lib/knapsack/distributors/base_distributor.rb', line 4

def report
  @report
end

#test_file_patternObject (readonly)

Returns the value of attribute test_file_pattern.



4
5
6
# File 'lib/knapsack/distributors/base_distributor.rb', line 4

def test_file_pattern
  @test_file_pattern
end

Instance Method Details

#all_testsObject



39
40
41
# File 'lib/knapsack/distributors/base_distributor.rb', line 39

def all_tests
  @all_tests ||= Dir.glob(test_file_pattern).uniq.sort
end

#assign_test_files_to_nodeObject



34
35
36
37
# File 'lib/knapsack/distributors/base_distributor.rb', line 34

def assign_test_files_to_node
  default_node_tests
  post_assign_test_files_to_node
end

#ci_node_indexObject



21
22
23
# File 'lib/knapsack/distributors/base_distributor.rb', line 21

def ci_node_index
  @ci_node_index.to_i
end

#ci_node_totalObject



17
18
19
# File 'lib/knapsack/distributors/base_distributor.rb', line 17

def ci_node_total
  @ci_node_total.to_i
end

#tests_for_current_nodeObject



25
26
27
# File 'lib/knapsack/distributors/base_distributor.rb', line 25

def tests_for_current_node
  tests_for_node(ci_node_index)
end

#tests_for_node(node_index) ⇒ Object



29
30
31
32
# File 'lib/knapsack/distributors/base_distributor.rb', line 29

def tests_for_node(node_index)
  assign_test_files_to_node
  post_tests_for_node(node_index)
end