Sha256: 03e781099759380aa5469e0b41b7e3b59bb963d03988fa56cec1c0ec38da1d86

Contents?: true

Size: 1.66 KB

Versions: 3

Compression:

Stored size: 1.66 KB

Contents

module Mutest
  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]
      def self.build(output)
        tput = Tput.detect
        tty = output.respond_to?(:tty?) && output.tty?
        format =
          if !Mutest.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 # Mutest

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mutest-0.0.9 lib/mutest/reporter/cli.rb
mutest-0.0.8 lib/mutest/reporter/cli.rb
mutest-0.0.7 lib/mutest/reporter/cli.rb