Sha256: b828f6185618b7e38b8d73ed265a9c9c88a5bc336698da986df3e36cbd65d910

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

module Knapsack
  module Distributors
    class BaseDistributor
      attr_reader :report, :node_tests, :test_file_pattern

      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

      def ci_node_total
        @ci_node_total.to_i
      end

      def ci_node_index
        @ci_node_index.to_i
      end

      def tests_for_current_node
        tests_for_node(ci_node_index)
      end

      def tests_for_node(node_index)
        assign_test_files_to_node
        post_tests_for_node(node_index)
      end

      def assign_test_files_to_node
        default_node_tests
        post_assign_test_files_to_node
      end

      def all_tests
        @all_tests ||= Dir[test_file_pattern].sort
      end

      protected

      def post_tests_for_node(node_index)
        raise NotImplementedError
      end

      def post_assign_test_files_to_node
        raise NotImplementedError
      end

      def default_node_tests
        raise NotImplementedError
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
knapsack-1.4.0 lib/knapsack/distributors/base_distributor.rb
knapsack-1.3.4 lib/knapsack/distributors/base_distributor.rb
knapsack-1.3.3 lib/knapsack/distributors/base_distributor.rb
knapsack-1.3.1 lib/knapsack/distributors/base_distributor.rb
knapsack-1.3.0 lib/knapsack/distributors/base_distributor.rb
knapsack-1.2.1 lib/knapsack/distributors/base_distributor.rb
knapsack-1.2.0 lib/knapsack/distributors/base_distributor.rb
knapsack-1.1.1 lib/knapsack/distributors/base_distributor.rb
knapsack-1.1.0 lib/knapsack/distributors/base_distributor.rb
knapsack-1.0.4 lib/knapsack/distributors/base_distributor.rb