diff --git a/lib/awesome_print.rb b/lib/awesome_print.rb index 0210810..c75166d 100644 --- a/lib/awesome_print.rb +++ b/lib/awesome_print.rb @@ -1,19 +1,26 @@ -# AwesomePrint might be loaded implicitly through ~/.irbrc or ~/.pryrc -# so do nothing for subsequent requires. -# -unless defined?(AwesomePrint::Inspector) - # FIXME: not sure we need these, but.. - require 'awesome_print/custom_defaults' +require 'awesome_print/formatters' +require 'awesome_print/inspector' +require 'awesome_print/formatter' +require 'awesome_print/version' - %w(active_support awesome_method_array string object class kernel).each do |file| - require "awesome_print/core_ext/#{file}" +module AwesomePrint + class << self + attr_accessor :defaults, :force_colors + + # Class accessor to force colorized output (ex. forked subprocess where TERM + # might be dumb). + #--------------------------------------------------------------------------- + def force_colors!(value = true) + @force_colors = value + end end - - require 'awesome_print/inspector' - require 'awesome_print/formatter' - - Dir["./lib/awesome_print/formatters/**/*.rb"].each { |f| require f } - - require 'awesome_print/version' - require 'awesome_print/core_ext/logger' if defined?(Logger) end + +# CORE EXTENSIONS... now that ap is loaded, inject awesome behavior into ruby +%w(awesome_method_array string object class kernel logger active_support).each do |file| + require "awesome_print/core_ext/#{file}" +end + +# FIXME: not sure we need these, but.. +require 'awesome_print/custom_defaults' + diff --git a/lib/awesome_print/core_ext/logger.rb b/lib/awesome_print/core_ext/logger.rb index 05809a1..5cfd7c8 100644 --- a/lib/awesome_print/core_ext/logger.rb +++ b/lib/awesome_print/core_ext/logger.rb @@ -11,5 +11,5 @@ module AwesomePrint end end -Logger.send(:include, AwesomePrint::Logger) +Logger.send(:include, AwesomePrint::Logger) if defined?(Logger) ActiveSupport::BufferedLogger.send(:include, AwesomePrint::Logger) if defined?(ActiveSupport::BufferedLogger) diff --git a/lib/awesome_print/custom_defaults.rb b/lib/awesome_print/custom_defaults.rb index aec402a..7a2193c 100644 --- a/lib/awesome_print/custom_defaults.rb +++ b/lib/awesome_print/custom_defaults.rb @@ -1,13 +1,5 @@ module AwesomePrint class << self - attr_accessor :defaults, :force_colors - - # Class accessor to force colorized output (ex. forked subprocess where TERM - # might be dumb). - #--------------------------------------------------------------------------- - def force_colors!(value = true) - @force_colors = value - end def console? boolean(defined?(IRB) || defined?(Pry)) diff --git a/lib/awesome_print/formatters.rb b/lib/awesome_print/formatters.rb index e549958..84484e1 100644 --- a/lib/awesome_print/formatters.rb +++ b/lib/awesome_print/formatters.rb @@ -1,15 +1,6 @@ module AwesomePrint module Formatters - require 'awesome_print/formatters/object_formatter' - require 'awesome_print/formatters/struct_formatter' - require 'awesome_print/formatters/hash_formatter' - require 'awesome_print/formatters/array_formatter' - require 'awesome_print/formatters/simple_formatter' - require 'awesome_print/formatters/method_formatter' - require 'awesome_print/formatters/class_formatter' - require 'awesome_print/formatters/dir_formatter' - require 'awesome_print/formatters/file_formatter' - require 'awesome_print/colorize' + Dir[File.join(__dir__, 'formatters', '**', '*.rb')].each { |f| require f } end end diff --git a/lib/awesome_print/registrar.rb b/lib/awesome_print/registrar.rb index a63475e..0edbb65 100644 --- a/lib/awesome_print/registrar.rb +++ b/lib/awesome_print/registrar.rb @@ -1,3 +1,5 @@ +require_relative 'formatter' + module AwesomePrint module Registrar diff --git a/lib/awesome_print/version.rb b/lib/awesome_print/version.rb index 13b6b49..7ce974b 100644 --- a/lib/awesome_print/version.rb +++ b/lib/awesome_print/version.rb @@ -5,6 +5,6 @@ module AwesomePrint end def self.version - '2.0.0.pre' + '2.0.0.pre2' end end diff --git a/spec/core_ext/logger_spec.rb b/spec/core_ext/logger_spec.rb index ed2d756..55fc1c9 100644 --- a/spec/core_ext/logger_spec.rb +++ b/spec/core_ext/logger_spec.rb @@ -1,9 +1,5 @@ require 'spec_helper' - -require 'logger' -require 'awesome_print/core_ext/logger' - RSpec.describe 'AwesomePrint logging extensions' do before(:all) do @logger = Logger.new('/dev/null') rescue Logger.new('nul') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cd83c53..33a41a0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,6 +30,8 @@ ExtVerifier.require_dependencies!( mongoid ) ) + +require 'logger' require 'nokogiri' require 'awesome_print'