Sha256: 00147d315070834f191b9052c2f8e6d1c6d1e345b389cdbf46e87a0220c47d59

Contents?: true

Size: 1.36 KB

Versions: 33

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

#
# Copyright (c) 2020-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Burner
  # A Pipeline execution can write main output, which is really an outline to whats happening,
  # step-by-step.  This is not meant to replace or be true logging, but serve more as a summary
  # for each of the jobs.  Each job can decide what it would like to include in this summary
  # and leverage an instance of this class for inclusion of that information.
  class Output
    RULER_LENGTH = 80

    attr_reader :id, :job_count, :outs

    def initialize(id: SecureRandom.uuid, outs: [$stdout])
      @id        = id
      @outs      = Array(outs)
      @job_count = 1
    end

    def ruler
      write('-' * RULER_LENGTH)

      self
    end

    def title(message)
      write("[#{job_count}] #{message}")

      @job_count += 1

      self
    end

    def detail(message)
      write("  - #{message}")

      self
    end

    def write(message)
      raw("[#{id} | #{Time.now.utc}] #{message}")

      self
    end

    def complete(time_in_seconds)
      detail("Completed in: #{time_in_seconds.round(3)} second(s)")

      self
    end

    private

    def raw(message)
      outs.each { |out| out.puts(message) }

      self
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
burner-1.12.0 lib/burner/output.rb
burner-1.11.0 lib/burner/output.rb
burner-1.10.0 lib/burner/output.rb
burner-1.9.0 lib/burner/output.rb
burner-1.9.0.pre.alpha lib/burner/output.rb
burner-1.8.0 lib/burner/output.rb
burner-1.7.0 lib/burner/output.rb
burner-1.7.0.pre.alpha lib/burner/output.rb
burner-1.6.0 lib/burner/output.rb
burner-1.6.0.pre.alpha lib/burner/output.rb
burner-1.5.0 lib/burner/output.rb
burner-1.5.0.pre.alpha lib/burner/output.rb
burner-1.4.0 lib/burner/output.rb
burner-1.4.0.pre.alpha lib/burner/output.rb
burner-1.3.0 lib/burner/output.rb
burner-1.3.0.pre.alpha lib/burner/output.rb
burner-1.2.0 lib/burner/output.rb
burner-1.1.0 lib/burner/output.rb
burner-1.1.0.pre.alpha lib/burner/output.rb
burner-1.0.0 lib/burner/output.rb