Sha256: 69307196d941c60129923e7245db450c0744aed6ac1fe2bccec4cec2281b2c47

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module Departure
  # Copies the ActiveRecord::Migration #say and #write plus a new
  # #write_no_newline to log the migration's status. It's not possible to reuse
  # the from ActiveRecord::Migration because the migration's instance can't be
  # seen from the connection adapter.
  class Logger

    def initialize(sanitizers)
      @sanitizers = sanitizers
    end

    # Outputs the message through the stdout, following the
    # ActiveRecord::Migration log format
    #
    # @param message [String]
    # @param subitem [Boolean] whether to show message as a nested log item
    def say(message, subitem = false)
      write "#{subitem ? "   ->" : "--"} #{message}"
    end

    # Outputs the text through the stdout adding a new line at the end
    #
    # @param text [String]
    def write(text = '')
      puts(sanitize(text))
    end

    # Outputs the text through the stdout without adding a new line at the end
    #
    # @param text [String]
    def write_no_newline(text)
      print(sanitize(text))
    end

    private

    attr_accessor :sanitizers

    def sanitize(text)
      sanitizers.inject(text) { |memo, sanitizer| sanitizer.execute(memo) }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
departure-4.0.1 lib/departure/logger.rb
departure-4.0.0 lib/departure/logger.rb
departure-2.0.1 lib/departure/logger.rb
departure-3.0.1 lib/departure/logger.rb
departure-3.0.0 lib/departure/logger.rb
departure-2.0.0 lib/departure/logger.rb