Sha256: 4740c7f6c36aeda6f9fe2729fbec822ccc48f3f5f161094198dd907d0e2b666a

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Roger
  module Helpers
    # Helper module for logging
    module Logging
      GRAY = "\e[37m".freeze
      RED  = "\e[31m".freeze

      # Write out a log message
      def log(part, msg, verbose = false, &block)
        shell = project.shell

        if !verbose || verbose && project.options[:verbose]
          shell.say(
            shell.set_color(part_string(part), GRAY) +
            " : " +
            msg
          )
        end

        log_block_indent(&block) if block_given?
      end

      def debug(part, msg, &block)
        log(part, msg, true, &block)
      end

      # Write out a warning message
      def warn(part, msg)
        shell = project.shell

        shell.say(
          shell.set_color(part_string(part), GRAY) +
          " : " +
          shell.set_color(msg, RED)
        )
      end

      protected

      def part_string(part)
        part.is_a?(String) ? part : part.class.to_s
      end

      def log_block_indent(&_block)
        project.shell.padding = project.shell.padding + 1
        yield
      ensure
        project.shell.padding = project.shell.padding - 1
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
roger-1.10.0 lib/roger/helpers/logging.rb
roger-1.9.1 lib/roger/helpers/logging.rb
roger-1.9.0 lib/roger/helpers/logging.rb
roger-1.8.0 lib/roger/helpers/logging.rb
roger-1.7.2 lib/roger/helpers/logging.rb
roger-1.7.1 lib/roger/helpers/logging.rb