1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Merge pull request #244 from waldyr/fix/improve-configurations

Improve configurations
This commit is contained in:
Waldyr de Souza 2016-07-05 10:17:57 -03:00 committed by GitHub
commit 83b0ca63e0
6 changed files with 83 additions and 68 deletions

View file

@ -4,10 +4,12 @@
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
$:.push File.expand_path('../lib', __FILE__)
require 'awesome_print/version'
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "awesome_print" s.name = "awesome_print"
s.version = "1.7.0" s.version = AwesomePrint.version
# s.platform = Gem::Platform::RUBY
s.authors = "Michael Dvorkin" s.authors = "Michael Dvorkin"
s.date = Time.now.strftime("%Y-%m-%d") s.date = Time.now.strftime("%Y-%m-%d")
s.email = "mike@dvorkin.net" s.email = "mike@dvorkin.net"

View file

@ -9,32 +9,33 @@
# #
unless defined?(AwesomePrint::Inspector) unless defined?(AwesomePrint::Inspector)
%w(array string method object class kernel).each do |file| %w(array string method object class kernel).each do |file|
require File.dirname(__FILE__) + "/awesome_print/core_ext/#{file}" require "awesome_print/core_ext/#{file}"
end end
require File.dirname(__FILE__) + "/awesome_print/inspector" require 'awesome_print/custom_defaults'
require File.dirname(__FILE__) + "/awesome_print/formatter" require 'awesome_print/inspector'
require File.dirname(__FILE__) + "/awesome_print/version" require 'awesome_print/formatter'
require File.dirname(__FILE__) + "/awesome_print/core_ext/logger" if defined?(Logger) require 'awesome_print/version'
require 'awesome_print/core_ext/logger' if defined?(Logger)
# #
# Load the following under normal circumstances as well as in Rails # Load the following under normal circumstances as well as in Rails
# console when required from ~/.irbrc or ~/.pryrc. # console when required from ~/.irbrc or ~/.pryrc.
# #
require File.dirname(__FILE__) + "/awesome_print/ext/active_record" if defined?(ActiveRecord) || AwesomePrint.rails_console? require 'awesome_print/ext/active_record' if defined?(ActiveRecord) || AwesomePrint.rails_console?
require File.dirname(__FILE__) + "/awesome_print/ext/active_support" if defined?(ActiveSupport) || AwesomePrint.rails_console? require 'awesome_print/ext/active_support' if defined?(ActiveSupport) || AwesomePrint.rails_console?
# #
# Load remaining extensions. # Load remaining extensions.
# #
if defined?(ActiveSupport.on_load) if defined?(ActiveSupport.on_load)
ActiveSupport.on_load(:action_view) do ActiveSupport.on_load(:action_view) do
require File.dirname(__FILE__) + "/awesome_print/ext/action_view" require 'awesome_print/ext/action_view'
end end
end end
require File.dirname(__FILE__) + "/awesome_print/ext/mongo_mapper" if defined?(MongoMapper) require 'awesome_print/ext/mongo_mapper' if defined?(MongoMapper)
require File.dirname(__FILE__) + "/awesome_print/ext/mongoid" if defined?(Mongoid) require 'awesome_print/ext/mongoid' if defined?(Mongoid)
require File.dirname(__FILE__) + "/awesome_print/ext/nokogiri" if defined?(Nokogiri) require 'awesome_print/ext/nokogiri' if defined?(Nokogiri)
require File.dirname(__FILE__) + "/awesome_print/ext/nobrainer" if defined?(NoBrainer) require 'awesome_print/ext/nobrainer' if defined?(NoBrainer)
require File.dirname(__FILE__) + "/awesome_print/ext/ripple" if defined?(Ripple) require 'awesome_print/ext/ripple' if defined?(Ripple)
require File.dirname(__FILE__) + "/awesome_print/ext/sequel" if defined?(Sequel) require 'awesome_print/ext/sequel' if defined?(Sequel)
require File.dirname(__FILE__) + "/awesome_print/ext/ostruct" if defined?(OpenStruct) require 'awesome_print/ext/ostruct' if defined?(OpenStruct)
end end

View file

@ -0,0 +1,48 @@
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?
!!(defined?(IRB) || defined?(Pry))
end
def rails_console?
console? && !!(defined?(Rails::Console) || ENV["RAILS_ENV"])
end
def diet_rb
IRB.formatter = Class.new(IRB::Formatter) do
def inspect_object(object)
object.ai
end
end.new
end
def usual_rb
IRB::Irb.class_eval do
def output_value
ap @context.last_value
rescue NoMethodError
puts "(Object doesn't support #ai)"
end
end
end
def irb!
return unless defined?(IRB)
IRB.version.include?("DietRB") ? diet_rb : usual_rb
end
def pry!
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
end
end
end

View file

@ -3,15 +3,7 @@
# Awesome Print is freely distributable under the terms of MIT license. # Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php # See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
require_relative "formatters/object_formatter" require 'awesome_print/formatters'
require_relative "formatters/hash_formatter"
require_relative "formatters/array_formatter"
require_relative "formatters/simple_formatter"
require_relative "formatters/method_formatter"
require_relative "formatters/class_formatter"
require_relative "formatters/dir_formatter"
require_relative "formatters/file_formatter"
require_relative "colorize"
module AwesomePrint module AwesomePrint
class Formatter class Formatter

View file

@ -0,0 +1,14 @@
module AwesomePrint
module Formatters
require 'awesome_print/formatters/object_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'
end
end

View file

@ -6,48 +6,6 @@
require_relative 'indentator' require_relative 'indentator'
module AwesomePrint module AwesomePrint
class << self # Class accessors for custom defaults.
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?
!!(defined?(IRB) || defined?(Pry))
end
def rails_console?
console? && !!(defined?(Rails::Console) || ENV['RAILS_ENV'])
end
def irb!
return unless defined?(IRB)
unless IRB.version.include?('DietRB')
IRB::Irb.class_eval do
def output_value
ap @context.last_value
rescue NoMethodError
puts "(Object doesn't support #ai)"
end
end
else # MacRuby
IRB.formatter = Class.new(IRB::Formatter) do
def inspect_object(object)
object.ai
end
end.new
end
end
def pry!
Pry.print = proc { |output, value| output.puts value.ai } if defined?(Pry)
end
end
class Inspector class Inspector
attr_accessor :options, :indentator attr_accessor :options, :indentator