Sha256: 750c3e5d8f4f22583df7dc4d3754527647869c360c6eae770d8a99e34925afb0

Contents?: true

Size: 1.71 KB

Versions: 8

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Mutant
  class Reporter
    # Reporter that reports in human readable format
    class CLI < self
      include Concord.new(:output, :format)

      # Build reporter
      #
      # @param [IO] output
      #
      # @return [Reporter::CLI]
      #
      # :reek:ManualDispatch
      def self.build(output)
        tput = Tput.detect
        tty = output.respond_to?(:tty?) && output.tty?
        format = if !Mutant.ci? && tty && tput
          Format::Framed.new(tty:  tty, tput: tput)
        else
          Format::Progressive.new(tty: tty)
        end
        new(output, format)
      end

      # Report start
      #
      # @param [Env::Bootstrap] env
      #
      # @return [self]
      def start(env)
        write(format.start(env))
        self
      end

      # Report progress object
      #
      # @param [Parallel::Status] status
      #
      # @return [self]
      def progress(status)
        write(format.progress(status))
        self
      end

      # Report delay in seconds
      #
      # TODO: Move this to a callback registration
      #
      # @return [Float]
      def delay
        format.delay
      end

      # Report warning
      #
      # @param [String] message
      #
      # @return [self]
      def warn(message)
        output.puts(message)
        self
      end

      # Report env
      #
      # @param [Result::Env] env
      #
      # @return [self]
      def report(env)
        Printer::EnvResult.call(output, env)
        self
      end

    private

      # Write output frame
      #
      # @param [String] frame
      #
      # @return [undefined]
      def write(frame)
        output.write(frame)
      end

    end # CLI
  end # Reporter
end # Mutant

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.8.24 lib/mutant/reporter/cli.rb
mutant-0.8.23 lib/mutant/reporter/cli.rb
mutant-0.8.22 lib/mutant/reporter/cli.rb
mutant-0.8.21 lib/mutant/reporter/cli.rb
mutant-0.8.20 lib/mutant/reporter/cli.rb
mutant-0.8.19 lib/mutant/reporter/cli.rb
mutant-0.8.18 lib/mutant/reporter/cli.rb
mutant-0.8.17 lib/mutant/reporter/cli.rb