Sha256: b6bb3d28d5227e203569dfe4ef7ef6e25a06778f9921cb9572272cd78341f0d5

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require "logger"

module RSpec
  module Parallel
    # Stores runtime configuration information.
    #
    # @!attribute concurrency
    #   @return [Integer]
    class Configuration
      DEFULT_AFTER_FORK = ->(_worker) {}

      def after_fork(&block)
        @after_fork_block = block_given? ? block : DEFULT_AFTER_FORK
      end

      def after_fork_block
        @after_fork_block ||= DEFULT_AFTER_FORK
      end

      # @return [Integer]
      def concurrency
        @concurrency ||=
          if File.exist?("/proc/cpuinfo")
            File.read("/proc/cpuinfo").split("\n").grep(/processor/).size
          elsif RUBY_PLATFORM =~ /darwin/
            `/usr/sbin/sysctl -n hw.activecpu`.to_i
          else
            2
          end
      end

      # @return [Logger]
      def logger
        @logger ||= Logger.new(STDERR).tap do |logger|
          logger.level = log_level
        end
      end

      # @return [Integer]
      def log_level
        @log_level ||= Logger::INFO
      end

      attr_writer :concurrency, :logger, :log_level
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parallel-rspec-0.1.1 lib/rspec/parallel/configuration.rb