Sha256: e6b1fd0284f7386e3f98ae57e9028ad335f09e3c8dca55eab12b9b3c9a579329

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true
##############################################################################
#                         Awesome Print Plugin
##############################################################################

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
begin
  require 'awesome_print'
  require 'io/console'

  module Kernel
    def sap(*messages)
      columns = if IO.console
                  IO.console.winsize[1]
                else
                  80
                end

      puts
      print "\e[1;37m"
      print " #{Time.now} ".center(columns, '*')
      print "\e[0m\n"
      puts
      root_path = if defined?(Rails)
                    Rails.root.to_s
                  else
                    `git rev-parse --show-toplevel`
                  end

      caller[0...5].each do |line|
        relative_line = line.gsub!(root_path.strip, '.')

        color = if relative_line == line
                  '35'
                else
                  '1;30'
                end

        print "\e[#{color}m"
        print line
        print "\e[0m\n"
      end

      puts

      Array(messages).each_with_index do |message, index|
        if message.respond_to?(:class)
          print "\e[32m"

          if defined?(::ActiveRecord::Base) && message.class.ancestors.include?(::ActiveRecord::Base)
            ap message.class
          else
            puts  "Class:      #{message.class}"
            print "Class Name: #{message.class.name}"
          end

          print "\e[0m\n"
          puts
        end

        ap(message)

        puts unless index + 1 == Array(messages).length
      end
    end
  end
rescue LoadError
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspeckled-0.0.18 lib/rspeckled/plugins/awesome_print.rb
rspeckled-0.0.17 lib/rspeckled/plugins/awesome_print.rb