Sha256: 7471742380d034b681d76ba8d5e2450742ac628fc20388a33a2afc298187aa04

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module WSDirector
  # Holds all results for all groups of clients
  class ResultsHolder
    def initialize
      @groups = Concurrent::Map.new
    end

    def success?
      @groups.values.all?(&:success?)
    end

    def groups
      @groups.values
    end

    def print_summary(printer: $stdout, colorize: false)
      single_group = groups.size == 1

      @groups.each do |group, result|
        color = result.success? ? :green : :red
        prefix = single_group ? "" : "Group #{group}: "

        msg = "#{prefix}#{result.total_count} clients, #{result.failures_count} failures\n"
        msg = msg.colorize(color) if colorize

        printer.puts(msg)

        unless result.success?
          print_errors(result.errors, printer: printer, colorize: colorize)
          printer.puts "\n"
        end
      end
    end

    def <<(result)
      @groups[result.group] = result
    end

    private

    def print_errors(errors, printer:, colorize:)
      printer.puts "\n"

      errors.each.with_index do |error, i|
        msg = "#{i + 1}) #{error}\n"
        msg = msg.colorize(:red) if colorize

        printer.puts msg
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wsdirector-core-1.1.0 lib/wsdirector/results_holder.rb
wsdirector-core-1.0.3 lib/wsdirector/results_holder.rb
wsdirector-core-1.0.2 lib/wsdirector/results_holder.rb
wsdirector-core-1.0.1 lib/wsdirector/results_holder.rb
wsdirector-core-1.0.0 lib/wsdirector/results_holder.rb