Sha256: 39ea98982f7a6537c302d16a9b99087dda79dd95a70b73215fbdf2e2d560e5f1

Contents?: true

Size: 1.16 KB

Versions: 10

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

10 entries across 10 versions & 2 rubygems

Version Path
departure-6.7.0 lib/departure/logger.rb
departure-6.6.0 lib/departure/logger.rb
departure-6.5.0 lib/departure/logger.rb
departure-6.4.0 lib/departure/logger.rb
departure-6.3.0 lib/departure/logger.rb
departure-76c9880-6.2.0 lib/departure/logger.rb
departure-6.2.0 lib/departure/logger.rb
departure-6.1.0 lib/departure/logger.rb
departure-6.0.0 lib/departure/logger.rb
departure-5.0.0 lib/departure/logger.rb