awesome_print-1.8.0/0000755000004100000410000000000013170662323014427 5ustar www-datawww-dataawesome_print-1.8.0/Rakefile0000644000004100000410000000070613170662323016077 0ustar www-datawww-datarequire 'rubygems' require 'bundler/setup' require 'bundler' Bundler::GemHelper.install_tasks task :default do if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/ Rake::Task['spec'].invoke else Rake::Task['appraise'].invoke end end task :appraise do exec 'appraisal install && appraisal rake' end desc 'Run all awesome_print gem specs' task :spec do # Run plain rspec command without RSpec::Core::RakeTask overrides. exec 'rspec -c spec' end awesome_print-1.8.0/Gemfile.lock0000644000004100000410000000217113170662323016652 0ustar www-datawww-dataPATH remote: . specs: awesome_print (1.8.0) GEM remote: https://rubygems.org/ specs: appraisal (2.2.0) bundler rake thor (>= 0.14.0) codeclimate-test-reporter (1.0.8) simplecov (<= 0.13) diff-lcs (1.3) docile (1.1.5) fakefs (0.11.0) json (2.1.0) mini_portile2 (2.2.0) nokogiri (1.8.0) mini_portile2 (~> 2.2.0) rake (12.0.0) rspec (3.6.0) rspec-core (~> 3.6.0) rspec-expectations (~> 3.6.0) rspec-mocks (~> 3.6.0) rspec-core (3.6.0) rspec-support (~> 3.6.0) rspec-expectations (3.6.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.6.0) rspec-mocks (3.6.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) simplecov (0.13.0) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.1) sqlite3 (1.3.13) thor (0.19.4) PLATFORMS ruby DEPENDENCIES appraisal awesome_print! codeclimate-test-reporter fakefs (>= 0.2.1) nokogiri (>= 1.6.5) rspec (>= 3.0.0) simplecov sqlite3 BUNDLED WITH 1.14.6 awesome_print-1.8.0/Gemfile0000644000004100000410000000014213170662323015717 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in awesome_print.gemspec gemspec awesome_print-1.8.0/spec/0000755000004100000410000000000013170662323015361 5ustar www-datawww-dataawesome_print-1.8.0/spec/core_ext/0000755000004100000410000000000013170662323017171 5ustar www-datawww-dataawesome_print-1.8.0/spec/core_ext/logger_spec.rb0000644000004100000410000000171413170662323022012 0ustar www-datawww-datarequire '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') end describe 'ap method' do it 'should awesome_inspect the given object' do object = double expect(object).to receive(:ai) @logger.ap object end describe 'the log level' do before do AwesomePrint.defaults = {} end it 'should fallback to the default :debug log level' do expect(@logger).to receive(:debug) @logger.ap(nil) end it 'should use the global user default if no level passed' do AwesomePrint.defaults = { log_level: :info } expect(@logger).to receive(:info) @logger.ap(nil) end it 'should use the passed in level' do expect(@logger).to receive(:warn) @logger.ap(nil, :warn) end end end end awesome_print-1.8.0/spec/core_ext/string_spec.rb0000644000004100000410000000132513170662323022037 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'String extensions' do [:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white].each_with_index do |color, i| it "should have #{color} color" do expect(color.to_s.send(color)).to eq("\e[1;#{30 + i}m#{color}\e[0m") end it "should have #{color}ish color" do expect(color.to_s.send(:"#{color}ish")).to eq("\e[0;#{30 + i}m#{color}\e[0m") end end it 'should have black and pale colors' do expect('black'.send(:black)).to eq('black'.send(:grayish)) expect('pale'.send(:pale)).to eq('pale'.send(:whiteish)) expect('pale'.send(:pale)).to eq("\e[0;37mpale\e[0m") expect('whiteish'.send(:whiteish)).to eq("\e[0;37mwhiteish\e[0m") end end awesome_print-1.8.0/spec/colors_spec.rb0000644000004100000410000000520413170662323020222 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint' do def stub_tty!(output = true, stream = STDOUT) if output stream.instance_eval { def tty?; true; end } else stream.instance_eval { def tty?; false; end } end end describe 'colorization' do PLAIN = '[ 1, :two, "three", [ nil, [ true, false ] ] ]' COLORIZED = "[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]" before do ENV['TERM'] = 'xterm-colors' ENV.delete('ANSICON') @arr = [1, :two, 'three', [nil, [true, false]]] end describe 'default settings (no forced colors)' do before do AwesomePrint.force_colors! false end it 'colorizes tty processes by default' do stub_tty! expect(@arr.ai(multiline: false)).to eq(COLORIZED) end it "colorizes processes with ENV['ANSICON'] by default" do begin stub_tty! term = ENV['ANSICON'] ENV['ANSICON'] = '1' expect(@arr.ai(multiline: false)).to eq(COLORIZED) ensure ENV['ANSICON'] = term end end it 'does not colorize tty processes running in dumb terminals by default' do begin stub_tty! term = ENV['TERM'] ENV['TERM'] = 'dumb' expect(@arr.ai(multiline: false)).to eq(PLAIN) ensure ENV['TERM'] = term end end it 'does not colorize subprocesses by default' do begin stub_tty! false expect(@arr.ai(multiline: false)).to eq(PLAIN) ensure stub_tty! end end end describe 'forced colors override' do before do AwesomePrint.force_colors! end it 'still colorizes tty processes' do stub_tty! expect(@arr.ai(multiline: false)).to eq(COLORIZED) end it "colorizes processes with ENV['ANSICON'] set to 0" do begin stub_tty! term = ENV['ANSICON'] ENV['ANSICON'] = '1' expect(@arr.ai(multiline: false)).to eq(COLORIZED) ensure ENV['ANSICON'] = term end end it 'colorizes dumb terminals' do begin stub_tty! term = ENV['TERM'] ENV['TERM'] = 'dumb' expect(@arr.ai(multiline: false)).to eq(COLORIZED) ensure ENV['TERM'] = term end end it 'colorizes subprocess' do begin stub_tty! false expect(@arr.ai(multiline: false)).to eq(COLORIZED) ensure stub_tty! end end end end end awesome_print-1.8.0/spec/spec_helper.rb0000644000004100000410000000557013170662323020206 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ # # Running specs from the command line: # $ rake spec # Entire spec suite. # $ rspec spec/objects_spec.rb # Individual spec file. # # NOTE: To successfully run specs with Ruby 1.8.6 the older versions of # Bundler and RSpec gems are required: # # $ gem install bundler -v=1.0.2 # $ gem install rspec -v=2.6.0 # require 'simplecov' SimpleCov.start $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each do |file| require file end ExtVerifier.require_dependencies!( %w( rails active_record action_view active_support/all mongoid mongo_mapper ripple nobrainer ) ) require 'nokogiri' require 'awesome_print' RSpec.configure do |config| config.disable_monkey_patching! # TODO: Make specs not order dependent # config.order = :random Kernel.srand config.seed config.filter_run focus: true config.run_all_when_everything_filtered = true config.expect_with :rspec do |expectations| expectations.syntax = :expect end config.mock_with :rspec do |mocks| mocks.syntax = :expect mocks.verify_partial_doubles = true end config.default_formatter = 'doc' if config.files_to_run.one? # Run before all examples. Using suite or all will not work as stubs are # killed after each example ends. config.before(:each) do |_example| stub_dotfile! end end # This matcher handles the normalization of objects to replace non deterministic # parts (such as object IDs) with simple placeholder strings before doing a # comparison with a given string. It's important that this method only matches # a string which strictly conforms to the expected object ID format. RSpec::Matchers.define :be_similar_to do |expected, options| match do |actual| options ||= {} @actual = normalize_object_id_strings(actual, options) values_match? expected, @actual end diffable end # Override the Object IDs with a placeholder so that we are only checking # that an ID is present and not that it matches a certain value. This is # necessary as the Object IDs are not deterministic. def normalize_object_id_strings(str, options) str = str.gsub(/#<(.*?):0x[a-f\d]+/, '#<\1:placeholder_id') unless options[:skip_standard] str = str.gsub(/BSON::ObjectId\('[a-f\d]{24}'\)/, 'placeholder_bson_id') unless options[:skip_bson] str end def stub_dotfile! allow_any_instance_of(AwesomePrint::Inspector) .to receive(:load_dotfile) .and_return(true) end def capture! standard = $stdout $stdout = StringIO.new yield ensure $stdout = standard end awesome_print-1.8.0/spec/active_record_helper.rb0000644000004100000410000000135213170662323022057 0ustar www-datawww-dataif ExtVerifier.has_rails? # Required to use the column support module Rails def self.env {} end end # Establish connection to in-memory SQLite DB ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:' # Create the users table ActiveRecord::Migration.verbose = false ActiveRecord::Migration.create_table :users do |t| t.string :name t.integer :rank t.boolean :admin t.datetime :created_at end ActiveRecord::Migration.create_table :emails do |t| t.references :user t.string :email_address end # Create models class User < ActiveRecord::Base; has_many :emails; end class SubUser < User; end class Email < ActiveRecord::Base; belongs_to :user; end end awesome_print-1.8.0/spec/objects_spec.rb0000644000004100000410000000751413170662323020360 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'Objects' do after do Object.instance_eval { remove_const :Hello } if defined?(Hello) end describe 'Formatting an object' do it 'attributes' do class Hello attr_reader :abra attr_writer :ca attr_accessor :dabra def initialize @abra = 1 @ca = 2 @dabra = 3 end end hello = Hello.new out = hello.ai(plain: true, raw: true) str = <<-EOS.strip # EOS expect(out).to be_similar_to(str) expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect) end it 'instance variables' do class Hello def initialize @abra = 1 @ca = 2 @dabra = 3 end end hello = Hello.new out = hello.ai(plain: true, raw: true) str = <<-EOS.strip # EOS expect(out).to be_similar_to(str) expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect) end it 'attributes and instance variables' do class Hello attr_reader :abra attr_writer :ca attr_accessor :dabra def initialize @abra = 1 @ca = 2 @dabra = 3 @scooby = 3 @dooby = 2 @doo = 1 end end hello = Hello.new out = hello.ai(plain: true, raw: true) str = <<-EOS.strip # EOS expect(out).to be_similar_to(str) expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect) end it 'without the plain options print the colorized values' do class Hello attr_reader :abra attr_writer :ca def initialize @abra = 1 @ca = 2 @dabra = 3 end end hello = Hello.new out = hello.ai(raw: true) str = <<-EOS.strip # EOS expect(out).to be_similar_to(str) expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect) end it 'with multine as false show inline values' do class Hello attr_reader :abra attr_writer :ca def initialize @abra = 1 @ca = 2 @dabra = 3 end end hello = Hello.new out = hello.ai(multiline: false, plain: true, raw: true) str = <<-EOS.strip # EOS expect(out).to be_similar_to(str) expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect) end it 'without the sort_vars option does not sort instance variables' do class Hello attr_reader :abra attr_writer :ca attr_accessor :dabra def initialize @abra = 1 @ca = 2 @dabra = 3 @scooby = 3 @dooby = 2 @doo = 1 end def instance_variables [:@scooby, :@dooby, :@doo, :@abra, :@ca, :@dabra] end end hello = Hello.new out = hello.ai(plain: true, raw: true, sort_vars: false) str = <<-EOS.strip # EOS expect(out).to be_similar_to(str) expect(hello.ai(plain: true, raw: false)).to eq(hello.inspect) end end end awesome_print-1.8.0/spec/methods_spec.rb0000644000004100000410000003403013170662323020363 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'Single method' do after do Object.instance_eval { remove_const :Hello } if defined?(Hello) end it 'plain: should handle a method with no arguments' do method = ''.method(:upcase) expect(method.ai(plain: true)).to eq('String#upcase()') end it 'color: should handle a method with no arguments' do method = ''.method(:upcase) expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mupcase\e[0m\e[0;37m()\e[0m") end it 'plain: should handle a method with one argument' do method = ''.method(:include?) expect(method.ai(plain: true)).to eq('String#include?(arg1)') end it 'color: should handle a method with one argument' do method = ''.method(:include?) expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35minclude?\e[0m\e[0;37m(arg1)\e[0m") end it 'plain: should handle a method with two arguments' do method = ''.method(:tr) expect(method.ai(plain: true)).to eq('String#tr(arg1, arg2)') end it 'color: should handle a method with two arguments' do method = ''.method(:tr) expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35mtr\e[0m\e[0;37m(arg1, arg2)\e[0m") end it 'plain: should handle a method with multiple arguments' do method = ''.method(:split) expect(method.ai(plain: true)).to eq('String#split(*arg1)') end it 'color: should handle a method with multiple arguments' do method = ''.method(:split) expect(method.ai).to eq("\e[1;33mString\e[0m#\e[0;35msplit\e[0m\e[0;37m(*arg1)\e[0m") end it 'plain: should handle a method defined in mixin' do method = ''.method(:is_a?) expect(method.ai(plain: true)).to eq('String (Kernel)#is_a?(arg1)') end it 'color: should handle a method defined in mixin' do method = ''.method(:is_a?) expect(method.ai).to eq("\e[1;33mString (Kernel)\e[0m#\e[0;35mis_a?\e[0m\e[0;37m(arg1)\e[0m") end it 'plain: should handle an unbound method' do class Hello def world; end end method = Hello.instance_method(:world) expect(method.ai(plain: true)).to eq('Hello (unbound)#world()') end it 'color: should handle an unbound method' do class Hello def world(a, b); end end method = Hello.instance_method(:world) if RUBY_VERSION < '1.9.2' expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(arg1, arg2)\e[0m") else expect(method.ai).to eq("\e[1;33mHello (unbound)\e[0m#\e[0;35mworld\e[0m\e[0;37m(a, b)\e[0m") end end end RSpec.describe 'Object methods' do after do Object.instance_eval { remove_const :Hello } if defined?(Hello) end describe 'object.methods' do it 'index: should handle object.methods' do out = nil.methods.ai(plain: true).split("\n").grep(/is_a\?/).first expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/) end it 'no index: should handle object.methods' do out = nil.methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/) end end describe 'object.public_methods' do it 'index: should handle object.public_methods' do out = nil.public_methods.ai(plain: true).split("\n").grep(/is_a\?/).first expect(out).to match(/^\s+\[\s*\d+\]\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/) end it 'no index: should handle object.public_methods' do out = nil.public_methods.ai(plain: true, index: false).split("\n").grep(/is_a\?/).first expect(out).to match(/^\s+is_a\?\(arg1\)\s+NilClass \(Kernel\)$/) end end describe 'object.private_methods' do it 'index: should handle object.private_methods' do out = nil.private_methods.ai(plain: true).split("\n").grep(/sleep/).first expect(out).to match(/^\s+\[\s*\d+\]\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/) end it 'no index: should handle object.private_methods' do out = nil.private_methods.ai(plain: true, index: false).split("\n").grep(/sleep/).first expect(out).to match(/^\s+sleep\(\*arg1\)\s+NilClass \(Kernel\)$/) end end describe 'object.protected_methods' do it 'index: should handle object.protected_methods' do class Hello protected def m1; end def m2; end end expect(Hello.new.protected_methods.ai(plain: true)).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n]") end it 'no index: should handle object.protected_methods' do class Hello protected def m3(a, b); end end if RUBY_VERSION < '1.9.2' expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(arg1, arg2) Hello\n]") else expect(Hello.new.protected_methods.ai(plain: true, index: false)).to eq("[\n m3(a, b) Hello\n]") end end end describe 'object.private_methods' do it 'index: should handle object.private_methods' do class Hello private def m1; end def m2; end end out = Hello.new.private_methods.ai(plain: true).split("\n").grep(/m\d/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/) expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/) end it 'no index: should handle object.private_methods' do class Hello private def m3(a, b); end end out = Hello.new.private_methods.ai(plain: true).split("\n").grep(/m\d/) if RUBY_VERSION < '1.9.2' expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(arg1, arg2\)\s+Hello$/) else expect(out.first).to match(/^\s+\[\s*\d+\]\s+m3\(a, b\)\s+Hello$/) end end end describe 'object.singleton_methods' do it 'index: should handle object.singleton_methods' do class Hello class << self def m1; end def m2; end end end out = Hello.singleton_methods.ai(plain: true).split("\n").grep(/m\d/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/) expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello$/) end it 'no index: should handle object.singleton_methods' do class Hello def self.m3(a, b); end end out = Hello.singleton_methods.ai(plain: true, index: false).split("\n").grep(/m\d/) if RUBY_VERSION < '1.9.2' expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello$/) else expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello$/) end end end end RSpec.describe 'Class methods' do after do Object.instance_eval { remove_const :Hello } if defined?(Hello) end describe 'class.instance_methods' do it 'index: should handle unbound class.instance_methods' do class Hello def m1; end def m2; end end out = Hello.instance_methods.ai(plain: true).split("\n").grep(/m\d/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/) expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/) end it 'no index: should handle unbound class.instance_methods' do class Hello def m3(a, b); end end out = Hello.instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/) if RUBY_VERSION < '1.9.2' expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) else expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end end describe 'class.public_instance_methods' do it 'index: should handle class.public_instance_methods' do class Hello def m1; end def m2; end end out = Hello.public_instance_methods.ai(plain: true).split("\n").grep(/m\d/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/) expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/) end it 'no index: should handle class.public_instance_methods' do class Hello def m3(a, b); end end out = Hello.public_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/) if RUBY_VERSION < '1.9.2' expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) else expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end end describe 'class.protected_instance_methods' do it 'index: should handle class.protected_instance_methods' do class Hello protected def m1; end def m2; end end out = Hello.protected_instance_methods.ai(plain: true).split("\n").grep(/m\d/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/) expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/) end it 'no index: should handle class.protected_instance_methods' do class Hello protected def m3(a, b); end end out = Hello.protected_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/) if RUBY_VERSION < '1.9.2' expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) else expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end end describe 'class.private_instance_methods' do it 'index: should handle class.private_instance_methods' do class Hello private def m1; end def m2; end end out = Hello.private_instance_methods.ai(plain: true).split("\n").grep(/m\d/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello\s\(unbound\)$/) expect(out.last).to match(/^\s+\[\s*\d+\]\s+m2\(\)\s+Hello\s\(unbound\)$/) end it 'no index: should handle class.private_instance_methods' do class Hello private def m3(a, b); end end out = Hello.private_instance_methods.ai(plain: true, index: false).split("\n").grep(/m\d/) if RUBY_VERSION < '1.9.2' expect(out.first).to match(/^\s+m3\(arg1, arg2\)\s+Hello\s\(unbound\)$/) else expect(out.first).to match(/^\s+m3\(a, b\)\s+Hello\s\(unbound\)$/) end end end end if RUBY_VERSION >= '1.9.2' RSpec.describe 'Ruby 1.9.2+ Method#parameters' do before do stub_dotfile! end after do Object.instance_eval { remove_const :Hello } if defined?(Hello) end it '()' do class Hello def m1; end end out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\)\s+Hello$/) end it ':req' do class Hello def m1(a, b, c); end end out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, b, c\)\s+Hello$/) end it ':opt' do class Hello def m1(a, b = 1, c = 2); end # m1(a, *b, *c) end out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, \*c\)\s+Hello$/) end it ':rest' do class Hello def m1(*a); end # m1(*a) end out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(\*a\)\s+Hello$/) end it ':block' do class Hello def m1(a, b = nil, &blk); end # m1(a, *b, &blk) end out = Hello.new.methods.ai(plain: true).split("\n").grep(/m1/) expect(out.first).to match(/^\s+\[\s*\d+\]\s+m1\(a, \*b, &blk\)\s+Hello$/) end end end RSpec.describe 'Methods arrays' do after do Object.instance_eval { remove_const :Hello } if defined?(Hello) Object.instance_eval { remove_const :World } if defined?(World) end it 'obj1.methods - obj2.methods should be awesome printed' do stub_dotfile! class Hello def self.m1; end end out = (Hello.methods - Class.methods).ai(plain: true) expect(out).to eq("[\n [0] m1() Hello\n]") end it 'obj1.methods & obj2.methods should be awesome printed' do stub_dotfile! class Hello def self.m1; end def self.m2; end end class World def self.m1; end end out = (Hello.methods & World.methods - Class.methods).ai(plain: true) expect(out).to eq("[\n [0] m1() Hello\n]") end it 'obj1.methods.grep(pattern) should be awesome printed' do stub_dotfile! class Hello def self.m1; end def self.m2; end def self.m3; end end out = Hello.methods.grep(/^m1$/).ai(plain: true) expect(out).to eq("[\n [0] m1() Hello\n]") out = Hello.methods.grep(/^m\d$/).ai(plain: true) expect(out).to eq("[\n [0] m1() Hello\n [1] m2() Hello\n [2] m3() Hello\n]") end it 'obj1.methods.grep(pattern, &block) should pass the matching string within the block' do class Hello def self.m_one; end def self.m_two; end end out = Hello.methods.sort.grep(/^m_(.+)$/) { $1.to_sym } expect(out).to eq([:one, :two]) end it 'obj1.methods.grep(pattern, &block) should be awesome printed' do stub_dotfile! class Hello def self.m0; end def self.none; end def self.m1; end def self.one; end end out = Hello.methods.grep(/^m(\d)$/) { %w(none one)[$1.to_i] }.ai(plain: true) expect(out).to eq("[\n [0] none() Hello\n [1] one() Hello\n]") end # See https://github.com/awesome-print/awesome_print/issues/30 for details. it 'grepping methods and converting them to_sym should work as expected' do class Hello private def him; end def his private_methods.grep(/^h..$/) { |n| n.to_sym } end def her private_methods.grep(/^.e.$/) { |n| n.to_sym } end end hello = Hello.new expect((hello.send(:his) - hello.send(:her)).sort_by { |x| x.to_s }).to eq([:him, :his]) end it 'appending garbage to methods array should not raise error' do arr = 42.methods << [:wtf] expect { arr.ai(plain: true) }.not_to raise_error if RUBY_VERSION < '1.9.2' expect(arr.ai(plain: true)).to match(/\s+wtf\(\?\)\s+\?/) # [ :wtf ].to_s => "wtf" else expect(arr.ai(plain: true)).to match(/\s+\[:wtf\]\(\?\)\s+\?/) # [ :wtf ].to_s => [:wtf] end end end awesome_print-1.8.0/spec/formats_spec.rb0000644000004100000410000004522613170662323020404 0ustar www-datawww-datarequire 'spec_helper' require 'bigdecimal' require 'rational' require 'set' RSpec.describe 'AwesomePrint' do describe 'Array' do before do @arr = [1, :two, 'three', [nil, [true, false]]] end it 'empty array' do expect([].ai).to eq('[]') end it 'plain multiline' do expect(@arr.ai(plain: true)).to eq <<-EOS.strip [ [0] 1, [1] :two, [2] "three", [3] [ [0] nil, [1] [ [0] true, [1] false ] ] ] EOS end it 'plain multiline without index' do expect(@arr.ai(plain: true, index: false)).to eq <<-EOS.strip [ 1, :two, "three", [ nil, [ true, false ] ] ] EOS end it 'plain multiline indented' do expect(@arr.ai(plain: true, indent: 2)).to eq <<-EOS.strip [ [0] 1, [1] :two, [2] "three", [3] [ [0] nil, [1] [ [0] true, [1] false ] ] ] EOS end it 'plain multiline indented without index' do expect(@arr.ai(plain: true, indent: 2, index: false)).to eq <<-EOS.strip [ 1, :two, "three", [ nil, [ true, false ] ] ] EOS end it 'plain single line' do expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, :two, "three", [ nil, [ true, false ] ] ]') end it 'colored multiline (default)' do expect(@arr.ai).to eq <<-EOS.strip [ \e[1;37m[0] \e[0m\e[1;34m1\e[0m, \e[1;37m[1] \e[0m\e[0;36m:two\e[0m, \e[1;37m[2] \e[0m\e[0;33m\"three\"\e[0m, \e[1;37m[3] \e[0m[ \e[1;37m[0] \e[0m\e[1;31mnil\e[0m, \e[1;37m[1] \e[0m[ \e[1;37m[0] \e[0m\e[1;32mtrue\e[0m, \e[1;37m[1] \e[0m\e[1;31mfalse\e[0m ] ] ] EOS end it 'colored multiline indented' do expect(@arr.ai(indent: 8)).to eq <<-EOS.strip [ \e[1;37m[0] \e[0m\e[1;34m1\e[0m, \e[1;37m[1] \e[0m\e[0;36m:two\e[0m, \e[1;37m[2] \e[0m\e[0;33m\"three\"\e[0m, \e[1;37m[3] \e[0m[ \e[1;37m[0] \e[0m\e[1;31mnil\e[0m, \e[1;37m[1] \e[0m[ \e[1;37m[0] \e[0m\e[1;32mtrue\e[0m, \e[1;37m[1] \e[0m\e[1;31mfalse\e[0m ] ] ] EOS end it 'colored single line' do expect(@arr.ai(multiline: false)).to eq("[ \e[1;34m1\e[0m, \e[0;36m:two\e[0m, \e[0;33m\"three\"\e[0m, [ \e[1;31mnil\e[0m, [ \e[1;32mtrue\e[0m, \e[1;31mfalse\e[0m ] ] ]") end end #------------------------------------------------------------------------------ describe 'Nested Array' do before do @arr = [1, 2] @arr << @arr end it 'plain multiline' do expect(@arr.ai(plain: true)).to eq <<-EOS.strip [ [0] 1, [1] 2, [2] [...] ] EOS end it 'plain multiline without index' do expect(@arr.ai(plain: true, index: false)).to eq <<-EOS.strip [ 1, 2, [...] ] EOS end it 'plain single line' do expect(@arr.ai(plain: true, multiline: false)).to eq('[ 1, 2, [...] ]') end end #------------------------------------------------------------------------------ describe 'Limited Output Array' do before(:each) do @arr = (1..1000).to_a end it 'plain limited output large' do expect(@arr.ai(plain: true, limit: true)).to eq <<-EOS.strip [ [ 0] 1, [ 1] 2, [ 2] 3, [ 3] .. [996], [997] 998, [998] 999, [999] 1000 ] EOS end it 'plain limited output small' do @arr = @arr[0..3] expect(@arr.ai(plain: true, limit: true)).to eq <<-EOS.strip [ [0] 1, [1] 2, [2] 3, [3] 4 ] EOS end it 'plain limited output with 10 lines' do expect(@arr.ai(plain: true, limit: 10)).to eq <<-EOS.strip [ [ 0] 1, [ 1] 2, [ 2] 3, [ 3] 4, [ 4] 5, [ 5] .. [995], [996] 997, [997] 998, [998] 999, [999] 1000 ] EOS end it 'plain limited output with 11 lines' do expect(@arr.ai(plain: true, limit: 11)).to eq <<-EOS.strip [ [ 0] 1, [ 1] 2, [ 2] 3, [ 3] 4, [ 4] 5, [ 5] .. [994], [995] 996, [996] 997, [997] 998, [998] 999, [999] 1000 ] EOS end end #------------------------------------------------------------------------------ describe 'Limited Output Hash' do before(:each) do @hash = ('a'..'z').inject({}) { |h, v| h.merge({ v => v.to_sym }) } end it 'plain limited output' do expect(@hash.ai(sort_keys: true, plain: true, limit: true)).to eq <<-EOS.strip { "a" => :a, "b" => :b, "c" => :c, "d" => :d .. "w" => :w, "x" => :x, "y" => :y, "z" => :z } EOS end end #------------------------------------------------------------------------------ describe 'Hash' do before do @hash = { 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } } end it 'empty hash' do expect({}.ai).to eq('{}') end it 'plain multiline' do expect(@hash.ai(plain: true)).to eq <<-EOS.strip { 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } } EOS end it 'new hash syntax' do expect(@hash.ai(plain: true, ruby19_syntax: true)).to eq <<-EOS.strip { 1 => { sym: { "str" => { [ 1, 2, 3 ] => { { k: :v } => Hash < Object } } } } } EOS end it 'plain multiline indented' do expect(@hash.ai(plain: true, indent: 1)).to eq <<-EOS.strip { 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } } EOS end it 'plain single line' do expect(@hash.ai(plain: true, multiline: false)).to eq('{ 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } }') end it 'colored multiline (default)' do expect(@hash.ai).to eq <<-EOS.strip { 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } } EOS end it 'colored with new hash syntax' do expect(@hash.ai(ruby19_syntax: true)).to eq <<-EOS.strip { 1\e[0;37m => \e[0m{ sym\e[0;37m: \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { k: :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } } EOS end it 'colored multiline indented' do expect(@hash.ai(indent: 2)).to eq <<-EOS.strip { 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } } EOS end it 'colored single line' do expect(@hash.ai(multiline: false)).to eq("{ 1\e[0;37m => \e[0m{ :sym\e[0;37m => \e[0m{ \"str\"\e[0;37m => \e[0m{ [ 1, 2, 3 ]\e[0;37m => \e[0m{ { :k => :v }\e[0;37m => \e[0m\e[1;33mHash < Object\e[0m } } } } }") end end #------------------------------------------------------------------------------ describe 'Nested Hash' do before do @hash = {} @hash[:a] = @hash end it 'plain multiline' do expect(@hash.ai(plain: true)).to eq <<-EOS.strip { :a => {...} } EOS end it 'plain single line' do expect(@hash.ai(plain: true, multiline: false)).to eq('{ :a => {...} }') end end #------------------------------------------------------------------------------ describe 'Hash with several keys' do before do @hash = { 'b' => 'b', :a => 'a', :z => 'z', 'alpha' => 'alpha' } end it 'plain multiline' do out = @hash.ai(plain: true) if RUBY_VERSION.to_f < 1.9 # Order of @hash keys is not guaranteed. expect(out).to match(/^\{[^\}]+\}/m) expect(out).to match(/ "b" => "b",?/) expect(out).to match(/ :a => "a",?/) expect(out).to match(/ :z => "z",?/) expect(out).to match(/ "alpha" => "alpha",?$/) else expect(out).to eq <<-EOS.strip { "b" => "b", :a => "a", :z => "z", "alpha" => "alpha" } EOS end end it 'plain multiline with sorted keys' do expect(@hash.ai(plain: true, sort_keys: true)).to eq <<-EOS.strip { :a => "a", "alpha" => "alpha", "b" => "b", :z => "z" } EOS end end #------------------------------------------------------------------------------ describe 'Negative options[:indent]' do # # With Ruby < 1.9 the order of hash keys is not defined so we can't # reliably compare the output string. # it 'hash keys must be left aligned' do hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' } out = hash.ai(plain: true, indent: -4, sort_keys: true) expect(out).to eq <<-EOS.strip { [ 0, 0, 255 ] => :yellow, "magenta" => "rgb(255, 0, 255)", :red => "rgb(255, 0, 0)" } EOS end it 'nested hash keys should be indented (array of hashes)' do arr = [{ a: 1, bb: 22, ccc: 333 }, { 1 => :a, 22 => :bb, 333 => :ccc }] out = arr.ai(plain: true, indent: -4, sort_keys: true) expect(out).to eq <<-EOS.strip [ [0] { :a => 1, :bb => 22, :ccc => 333 }, [1] { 1 => :a, 22 => :bb, 333 => :ccc } ] EOS end it 'nested hash keys should be indented (hash of hashes)' do arr = { first: { a: 1, bb: 22, ccc: 333 }, second: { 1 => :a, 22 => :bb, 333 => :ccc } } out = arr.ai(plain: true, indent: -4, sort_keys: true) expect(out).to eq <<-EOS.strip { :first => { :a => 1, :bb => 22, :ccc => 333 }, :second => { 1 => :a, 22 => :bb, 333 => :ccc } } EOS end end #------------------------------------------------------------------------------ describe 'Class' do it 'should show superclass (plain)' do expect(self.class.ai(plain: true)).to eq("#{self.class} < #{self.class.superclass}") end it 'should show superclass (color)' do expect(self.class.ai).to eq("#{self.class} < #{self.class.superclass}".yellow) end end #------------------------------------------------------------------------------ describe 'File' do it 'should display a file (plain)' do File.open(__FILE__, 'r') do |f| expect(f.ai(plain: true)).to eq("#{f.inspect}\n" << `ls -alF #{f.path}`.chop) end end end #------------------------------------------------------------------------------ describe 'Dir' do it 'should display a direcory (plain)' do Dir.open(File.dirname(__FILE__)) do |d| expect(d.ai(plain: true)).to eq("#{d.inspect}\n" << `ls -alF #{d.path}`.chop) end end end #------------------------------------------------------------------------------ describe 'BigDecimal and Rational' do it 'should present BigDecimal object with arbitrary precision' do big = BigDecimal('201020102010201020102010201020102010.4') expect(big.ai(plain: true)).to eq('201020102010201020102010201020102010.4') end it 'should present Rational object with arbitrary precision' do rat = Rational(201020102010201020102010201020102010, 2) out = rat.ai(plain: true) # # Ruby 1.9 slightly changed the format of Rational#to_s, see # http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3 and # http://www.ruby-forum.com/topic/189397 # if RUBY_VERSION < '1.9' expect(out).to eq('100510051005100510051005100510051005') else expect(out).to eq('100510051005100510051005100510051005/1') end end end #------------------------------------------------------------------------------ describe 'Utility methods' do it 'should merge options' do ap = AwesomePrint::Inspector.new ap.send(:merge_options!, { color: { array: :black }, indent: 0 }) options = ap.instance_variable_get('@options') expect(options[:color][:array]).to eq(:black) expect(options[:indent]).to eq(0) end end #------------------------------------------------------------------------------ describe 'Set' do before do @arr = [1, :two, 'three'] @set = Set.new(@arr) end it 'empty set' do expect(Set.new.ai).to eq([].ai) end if RUBY_VERSION > '1.9' it 'plain multiline' do expect(@set.ai(plain: true)).to eq(@arr.ai(plain: true)) end it 'plain multiline indented' do expect(@set.ai(plain: true, indent: 1)).to eq(@arr.ai(plain: true, indent: 1)) end it 'plain single line' do expect(@set.ai(plain: true, multiline: false)).to eq(@arr.ai(plain: true, multiline: false)) end it 'colored multiline (default)' do expect(@set.ai).to eq(@arr.ai) end else # Prior to Ruby 1.9 the order of set values is unpredicatble. it 'plain multiline' do expect(@set.sort_by { |x| x.to_s }.ai(plain: true)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true)) end it 'plain multiline indented' do expect(@set.sort_by { |x| x.to_s }.ai(plain: true, indent: 1)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true, indent: 1)) end it 'plain single line' do expect(@set.sort_by { |x| x.to_s }.ai(plain: true, multiline: false)).to eq(@arr.sort_by { |x| x.to_s }.ai(plain: true, multiline: false)) end it 'colored multiline (default)' do expect(@set.sort_by { |x| x.to_s }.ai).to eq(@arr.sort_by { |x| x.to_s }.ai) end end end #------------------------------------------------------------------------------ describe 'Struct' do before do @struct = unless defined?(Struct::SimpleStruct) Struct.new('SimpleStruct', :name, :address).new else Struct::SimpleStruct.new end @struct.name = 'Herman Munster' @struct.address = '1313 Mockingbird Lane' end it 'empty struct' do expect(Struct.new('EmptyStruct').ai).to eq("\e[1;33mStruct::EmptyStruct < Struct\e[0m") end it 'plain multiline' do s1 = <<-EOS.strip address = \"1313 Mockingbird Lane\", name = \"Herman Munster\" EOS s2 = <<-EOS.strip name = \"Herman Munster\", address = \"1313 Mockingbird Lane\" EOS expect(@struct.ai(plain: true)).to satisfy { |out| out.match(s1) || out.match(s2) } end it 'plain multiline indented' do s1 = <<-EOS.strip address = "1313 Mockingbird Lane", name = "Herman Munster" EOS s2 = <<-EOS.strip name = "Herman Munster", address = "1313 Mockingbird Lane" EOS expect(@struct.ai(plain: true, indent: 1)).to satisfy { |out| out.match(s1) || out.match(s2) } end it 'plain single line' do s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"' s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"' expect(@struct.ai(plain: true, multiline: false)).to satisfy { |out| out.match(s1) || out.match(s2) } end it 'colored multiline (default)' do s1 = <<-EOS.strip address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m, name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m EOS s2 = <<-EOS.strip name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m, address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m EOS expect(@struct.ai).to satisfy { |out| out.include?(s1) || out.include?(s2) } end end #------------------------------------------------------------------------------ describe 'Inherited from standard Ruby classes' do after do Object.instance_eval { remove_const :My } if defined?(My) end it 'inherited from Array should be displayed as Array' do class My < Array; end my = My.new([1, :two, 'three', [nil, [true, false]]]) expect(my.ai(plain: true)).to eq <<-EOS.strip [ [0] 1, [1] :two, [2] "three", [3] [ [0] nil, [1] [ [0] true, [1] false ] ] ] EOS end it 'inherited from Hash should be displayed as Hash' do class My < Hash; end my = My[{ 1 => { sym: { 'str' => { [1, 2, 3] => { { k: :v } => Hash } } } } }] expect(my.ai(plain: true)).to eq <<-EOS.strip { 1 => { :sym => { "str" => { [ 1, 2, 3 ] => { { :k => :v } => Hash < Object } } } } } EOS end it 'inherited from File should be displayed as File' do class My < File; end my = File.new('/dev/null') rescue File.new('nul') expect(my.ai(plain: true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop) end it 'inherited from Dir should be displayed as Dir' do class My < Dir; end require 'tmpdir' my = My.new(Dir.tmpdir) expect(my.ai(plain: true)).to eq("#{my.inspect}\n" << `ls -alF #{my.path}`.chop) end it 'should handle a class that defines its own #send method' do class My def send(arg1, arg2, arg3); end end my = My.new expect { my.methods.ai(plain: true) }.not_to raise_error end it 'should handle a class defines its own #method method (ex. request.method)' do class My def method 'POST' end end my = My.new expect { my.methods.ai(plain: true) }.not_to raise_error end describe 'should handle a class that defines its own #to_hash method' do it 'that takes arguments' do class My def to_hash(a, b) end end my = My.new expect { my.ai(plain: true) }.not_to raise_error end it 'that returns nil' do class My def to_hash() return nil end end my = My.new expect { my.ai(plain: true) }.not_to raise_error end it "that returns an object that doesn't support #keys" do class My def to_hash() object = Object.new object.define_singleton_method('[]') { return nil } return object end end my = My.new expect { my.ai(plain: true) }.not_to raise_error end it "that returns an object that doesn't support subscripting" do class My def to_hash() object = Object.new object.define_singleton_method(:keys) { return [:foo] } return object end end my = My.new expect { my.ai(plain: true) }.not_to raise_error end end end end awesome_print-1.8.0/spec/support/0000755000004100000410000000000013170662323017075 5ustar www-datawww-dataawesome_print-1.8.0/spec/support/active_record_data/0000755000004100000410000000000013170662323022677 5ustar www-datawww-dataawesome_print-1.8.0/spec/support/active_record_data/5_0_multi.txt0000644000004100000410000002511013170662323025234 0ustar www-datawww-data[ [0] # #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "admin", attr_reader :type = #, attr_reader :value_before_type_cast = false >, "created_at" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "created_at", attr_reader :type = #, attr_reader :value_before_type_cast = "1992-10-10 12:30:00" >, "id" => #, attr_reader :value_before_type_cast = nil >, "name" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "name", attr_reader :type = #, attr_reader :value_before_type_cast = "Diana" >, "rank" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "rank", attr_reader :type = #, attr_reader :value_before_type_cast = 1 > } >, attr_accessor :destroyed_by_association = nil >, [1] # #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "admin", attr_reader :type = #, attr_reader :value_before_type_cast = true >, "created_at" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "created_at", attr_reader :type = #, attr_reader :value_before_type_cast = "2003-05-26 14:15:00" >, "id" => #, attr_reader :value_before_type_cast = nil >, "name" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "name", attr_reader :type = #, attr_reader :value_before_type_cast = "Laura" >, "rank" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "rank", attr_reader :type = #, attr_reader :value_before_type_cast = 2 > } >, attr_accessor :destroyed_by_association = nil > ] awesome_print-1.8.0/spec/support/active_record_data/4_0_multi.txt0000644000004100000410000001770413170662323025245 0ustar www-datawww-data[ [0] # #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @column_types_override = nil, @destroyed = false, @marked_for_destruction = false, @new_record = true, @previously_changed = {}, @readonly = false, @reflects_state = [ [0] false ], @transaction_state = nil, @txn = nil, attr_accessor :attributes = { "admin" => false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } >, [1] # #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @column_types_override = nil, @destroyed = false, @marked_for_destruction = false, @new_record = true, @previously_changed = {}, @readonly = false, @reflects_state = [ [0] false ], @transaction_state = nil, @txn = nil, attr_accessor :attributes = { "admin" => true, "created_at" => "2003-05-26 14:15:00", "id" => nil, "name" => "Laura", "rank" => 2 }, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > ] awesome_print-1.8.0/spec/support/active_record_data/3_2_multi.txt0000644000004100000410000000277413170662323025247 0ustar www-datawww-data[ [0] # false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } >, [1] # true, "created_at" => "2003-05-26 14:15:00", "id" => nil, "name" => "Laura", "rank" => 2 }, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > ] awesome_print-1.8.0/spec/support/active_record_data/4_1_diana.txt0000644000004100000410000000706613170662323025170 0ustar www-datawww-data# #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @column_types_override = nil, @destroyed = false, @marked_for_destruction = false, @new_record = true, @readonly = false, @reflects_state = [ [0] false ], @transaction_state = nil, @txn = nil, attr_accessor :attributes = { "admin" => false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > awesome_print-1.8.0/spec/support/active_record_data/4_2_diana.txt0000644000004100000410000001113113170662323025155 0ustar www-datawww-data# false, "created_at" => 1992-10-10 12:30:00 UTC, "name" => "Diana", "rank" => 1 }, @readonly = false, @transaction_state = nil, @txn = nil, attr_accessor :attributes = # #, attr_reader :value = false, attr_reader :value_before_type_cast = false >, "created_at" => #, attr_reader :value = 1992-10-10 12:30:00 UTC, attr_reader :value_before_type_cast = "1992-10-10 12:30:00" >, "name" => #, attr_reader :value = "Diana", attr_reader :value_before_type_cast = "Diana" >, "rank" => #, attr_reader :value = 1, attr_reader :value_before_type_cast = 1 > }, @materialized = false, @types = { "admin" => #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @values = { "admin" => nil, "created_at" => nil, "id" => nil, "name" => nil, "rank" => nil } > >, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > awesome_print-1.8.0/spec/support/active_record_data/3_2_diana.txt0000644000004100000410000000123013170662323025153 0ustar www-datawww-data# false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > awesome_print-1.8.0/spec/support/active_record_data/5_0_diana.txt0000644000004100000410000001157213170662323025165 0ustar www-datawww-data# #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "admin", attr_reader :type = #, attr_reader :value_before_type_cast = false >, "created_at" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "created_at", attr_reader :type = #, attr_reader :value_before_type_cast = "1992-10-10 12:30:00" >, "id" => #, attr_reader :value_before_type_cast = nil >, "name" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "name", attr_reader :type = #, attr_reader :value_before_type_cast = "Diana" >, "rank" => #, attr_reader :value_before_type_cast = nil >, attr_reader :name = "rank", attr_reader :type = #, attr_reader :value_before_type_cast = 1 > } >, attr_accessor :destroyed_by_association = nil > awesome_print-1.8.0/spec/support/active_record_data/3_2_multi_legacy.txt0000644000004100000410000000302413170662323026560 0ustar www-datawww-data[ [0] # false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil }, attr_reader :mass_assignment_options = nil >, [1] # true, "created_at" => "2003-05-26 14:15:00", "id" => nil, "name" => "Laura", "rank" => 2 }, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil }, attr_reader :mass_assignment_options = nil > ] awesome_print-1.8.0/spec/support/active_record_data/3_2_diana_legacy.txt0000644000004100000410000000124413170662323026504 0ustar www-datawww-data# false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil }, attr_reader :mass_assignment_options = nil > awesome_print-1.8.0/spec/support/active_record_data/4_2_multi_legacy.txt0000644000004100000410000002434413170662323026571 0ustar www-datawww-data[ [0] # false, "created_at" => 1992-10-10 12:30:00 UTC, "name" => "Diana", "rank" => 1 }, @readonly = false, @transaction_state = nil, @txn = nil, attr_accessor :attributes = # #, attr_reader :value = false, attr_reader :value_before_type_cast = false >, "created_at" => #, attr_reader :value = 1992-10-10 12:30:00 UTC, attr_reader :value_before_type_cast = "1992-10-10 12:30:00" >, "name" => #, attr_reader :value = "Diana", attr_reader :value_before_type_cast = "Diana" >, "rank" => #, attr_reader :value = 1, attr_reader :value_before_type_cast = 1 > }, attr_reader :types = { "admin" => #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, attr_reader :values = { "admin" => nil, "created_at" => nil, "id" => nil, "name" => nil, "rank" => nil } > >, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } >, [1] # true, "created_at" => 2003-05-26 14:15:00 UTC, "name" => "Laura", "rank" => 2 }, @readonly = false, @transaction_state = nil, @txn = nil, attr_accessor :attributes = # #, attr_reader :value = true, attr_reader :value_before_type_cast = true >, "created_at" => #, attr_reader :value = 2003-05-26 14:15:00 UTC, attr_reader :value_before_type_cast = "2003-05-26 14:15:00" >, "name" => #, attr_reader :value = "Laura", attr_reader :value_before_type_cast = "Laura" >, "rank" => #, attr_reader :value = 2, attr_reader :value_before_type_cast = 2 > }, attr_reader :types = { "admin" => #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, attr_reader :values = { "admin" => nil, "created_at" => nil, "id" => nil, "name" => nil, "rank" => nil } > >, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > ] awesome_print-1.8.0/spec/support/active_record_data/4_2_diana_legacy.txt0000644000004100000410000001127113170662323026506 0ustar www-datawww-data# false, "created_at" => 1992-10-10 12:30:00 UTC, "name" => "Diana", "rank" => 1 }, @readonly = false, @transaction_state = nil, @txn = nil, attr_accessor :attributes = # #, attr_reader :value = false, attr_reader :value_before_type_cast = false >, "created_at" => #, attr_reader :value = 1992-10-10 12:30:00 UTC, attr_reader :value_before_type_cast = "1992-10-10 12:30:00" >, "name" => #, attr_reader :value = "Diana", attr_reader :value_before_type_cast = "Diana" >, "rank" => #, attr_reader :value = 1, attr_reader :value_before_type_cast = 1 > }, attr_reader :types = { "admin" => #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, attr_reader :values = { "admin" => nil, "created_at" => nil, "id" => nil, "name" => nil, "rank" => nil } > >, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > awesome_print-1.8.0/spec/support/active_record_data/4_0_diana.txt0000644000004100000410000000712413170662323025162 0ustar www-datawww-data# #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @column_types_override = nil, @destroyed = false, @marked_for_destruction = false, @new_record = true, @previously_changed = {}, @readonly = false, @reflects_state = [ [0] false ], @transaction_state = nil, @txn = nil, attr_accessor :attributes = { "admin" => false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > awesome_print-1.8.0/spec/support/active_record_data/4_2_multi.txt0000644000004100000410000002404413170662323025242 0ustar www-datawww-data[ [0] # false, "created_at" => 1992-10-10 12:30:00 UTC, "name" => "Diana", "rank" => 1 }, @readonly = false, @transaction_state = nil, @txn = nil, attr_accessor :attributes = # #, attr_reader :value = false, attr_reader :value_before_type_cast = false >, "created_at" => #, attr_reader :value = 1992-10-10 12:30:00 UTC, attr_reader :value_before_type_cast = "1992-10-10 12:30:00" >, "name" => #, attr_reader :value = "Diana", attr_reader :value_before_type_cast = "Diana" >, "rank" => #, attr_reader :value = 1, attr_reader :value_before_type_cast = 1 > }, @materialized = false, @types = { "admin" => #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @values = { "admin" => nil, "created_at" => nil, "id" => nil, "name" => nil, "rank" => nil } > >, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } >, [1] # true, "created_at" => 2003-05-26 14:15:00 UTC, "name" => "Laura", "rank" => 2 }, @readonly = false, @transaction_state = nil, @txn = nil, attr_accessor :attributes = # #, attr_reader :value = true, attr_reader :value_before_type_cast = true >, "created_at" => #, attr_reader :value = 2003-05-26 14:15:00 UTC, attr_reader :value_before_type_cast = "2003-05-26 14:15:00" >, "name" => #, attr_reader :value = "Laura", attr_reader :value_before_type_cast = "Laura" >, "rank" => #, attr_reader :value = 2, attr_reader :value_before_type_cast = 2 > }, @materialized = false, @types = { "admin" => #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @values = { "admin" => nil, "created_at" => nil, "id" => nil, "name" => nil, "rank" => nil } > >, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > ] awesome_print-1.8.0/spec/support/active_record_data/4_1_multi.txt0000644000004100000410000001760013170662323025241 0ustar www-datawww-data[ [0] # #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @column_types_override = nil, @destroyed = false, @marked_for_destruction = false, @new_record = true, @readonly = false, @reflects_state = [ [0] false ], @transaction_state = nil, @txn = nil, attr_accessor :attributes = { "admin" => false, "created_at" => "1992-10-10 12:30:00", "id" => nil, "name" => "Diana", "rank" => 1 }, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } >, [1] # #, "created_at" => #, "id" => #, "name" => #, "rank" => # }, @column_types_override = nil, @destroyed = false, @marked_for_destruction = false, @new_record = true, @readonly = false, @reflects_state = [ [0] false ], @transaction_state = nil, @txn = nil, attr_accessor :attributes = { "admin" => true, "created_at" => "2003-05-26 14:15:00", "id" => nil, "name" => "Laura", "rank" => 2 }, attr_accessor :destroyed_by_association = nil, attr_reader :association_cache = {}, attr_reader :changed_attributes = { "admin" => nil, "created_at" => nil, "name" => nil, "rank" => nil } > ] awesome_print-1.8.0/spec/support/active_record_data.rb0000644000004100000410000000110013170662323023214 0ustar www-datawww-datarequire 'pathname' class ActiveRecordData class << self data_file_selector = Pathname(File.dirname(__FILE__)).join('active_record_data', '*.txt') # Example generated method # data_filename = '/path/to/ap/spec/support/active_record_data/4_2_diana.txt' # # def self.raw_4_2_dana # File.read(data_filename).strip # end Dir[data_file_selector].each do |data_filename| method_name = Pathname(data_filename).basename('.txt') define_method(:"raw_#{method_name}") do File.read(data_filename).strip end end end end awesome_print-1.8.0/spec/support/rails_versions.rb0000644000004100000410000000156613170662323022474 0ustar www-datawww-datamodule RailsVersions def rails_version Gem::Version.new(Rails::VERSION::STRING) end def rails_5_0? Gem::Requirement.new('~> 5.0.0.racecar1').satisfied_by?(rails_version) end alias_method :activerecord_5_0?, :rails_5_0? def rails_4_2? Gem::Requirement.new('~> 4.2.0').satisfied_by?(rails_version) end alias_method :activerecord_4_2?, :rails_4_2? def rails_4_1? Gem::Requirement.new('~> 4.1.0').satisfied_by?(rails_version) end alias_method :activerecord_4_1?, :rails_4_1? def rails_4_0? Gem::Requirement.new('~> 4.0.0').satisfied_by?(rails_version) end alias_method :activerecord_4_0?, :rails_4_0? def rails_3_2? Gem::Requirement.new('~> 3.2.0').satisfied_by?(rails_version) end alias_method :activerecord_3_2?, :rails_3_2? end RSpec.configure do |config| config.include(RailsVersions) config.extend(RailsVersions) end awesome_print-1.8.0/spec/support/ext_verifier.rb0000644000004100000410000000133613170662323022120 0ustar www-datawww-datamodule ExtVerifier def require_dependencies!(dependencies) dependencies.each do |dependency| begin require dependency rescue LoadError end end end module_function :require_dependencies! def has_rails? defined?(Rails) end module_function :has_rails? def has_mongoid? defined?(Mongoid) end module_function :has_mongoid? def has_mongo_mapper? defined?(MongoMapper) end module_function :has_mongo_mapper? def has_ripple? defined?(Ripple) end module_function :has_ripple? def has_nobrainer? defined?(NoBrainer) end module_function :has_nobrainer? end RSpec.configure do |config| config.include(ExtVerifier) config.extend(ExtVerifier) end awesome_print-1.8.0/spec/support/mongoid_versions.rb0000644000004100000410000000073413170662323023012 0ustar www-datawww-datamodule MongoidVersions def mongoid_version Gem::Version.new(Mongoid::VERSION) end def mongoid_4_0? Gem::Requirement.new('~> 4.0.0').satisfied_by?(mongoid_version) end def mongoid_3_0? Gem::Requirement.new('~> 3.0.0').satisfied_by?(mongoid_version) end def mongoid_3_1? Gem::Requirement.new('~> 3.1.0').satisfied_by?(mongoid_version) end end RSpec.configure do |config| config.include(MongoidVersions) config.extend(MongoidVersions) end awesome_print-1.8.0/spec/misc_spec.rb0000644000004100000410000002057013170662323017657 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint' do describe 'Misc' do it 'handle weird objects that return nil on inspect' do weird = Class.new do def inspect nil end end expect(weird.new.ai(plain: true)).to eq('') end it 'handle frozen object.inspect' do weird = Class.new do def inspect 'ice'.freeze end end expect(weird.new.ai(plain: false)).to eq('ice') end # See https://github.com/awesome-print/awesome_print/issues/35 it 'handle array grep when pattern contains / chapacter' do hash = { '1/x' => 1, '2//x' => :"2" } grepped = hash.keys.sort.grep(/^(\d+)\//) { $1 } expect(grepped.ai(plain: true, multiline: false)).to eq('[ "1", "2" ]') end # See https://github.com/awesome-print/awesome_print/issues/85 if RUBY_VERSION >= '1.8.7' it "handle array grep when a method is defined in C and thus doesn't have a binding" do arr = (0..6).to_a grepped = arr.grep(1..4, &:succ) expect(grepped.ai(plain: true, multiline: false)).to eq('[ 2, 3, 4, 5 ]') end end it 'returns value passed as a parameter' do object = rand allow(self).to receive(:puts) expect(ap object).to eq(object) end # Require different file name this time (lib/ap.rb vs. lib/awesome_print). it "several require 'awesome_print' should do no harm" do require File.expand_path(File.dirname(__FILE__) + '/../lib/ap') expect { rand.ai }.not_to raise_error end it 'format ENV as hash' do expect(ENV.ai(plain: true)).to eq(ENV.to_hash.ai(plain: true)) expect(ENV.ai).to eq(ENV.to_hash.ai) end # See https://github.com/awesome-print/awesome_print/issues/134 it 'IPAddr workaround' do require 'ipaddr' ipaddr = IPAddr.new('3ffe:505:2::1') expect(ipaddr.ai).to eq('#') end # See https://github.com/awesome-print/awesome_print/issues/139 it 'Object that overrides == and expects the :id method' do weird = Class.new do # Raises NoMethodError: undefined method `id' when "other" is nil or ENV. def ==(other) self.id == other.id end alias :eql? :== end expect { weird.new.ai }.not_to raise_error end end #------------------------------------------------------------------------------ describe 'HTML output' do it 'wraps ap output with plain
 tag' do
      markup = rand
      expect(markup.ai(html: true, plain: true)).to eq("
#{markup}
") end it 'wraps ap output with
 tag with colorized ' do
      markup = rand
      expect(markup.ai(html: true)).to eq(%Q|
#{markup}
|) end it 'wraps multiline ap output with
 tag with colorized ' do
      markup = [1, :two, 'three']
      expect(markup.ai(html: true)).to eq <<-EOS.strip_heredoc.strip
        
[
            [0] 1,
            [1] :two,
            [2] "three"
        ]
EOS end it 'wraps hash ap output with only an outer
 tag' do
      markup = [{ 'hello' => 'world' }]
      expect(markup.ai(html: true)).to eq <<-EOS.strip_heredoc.strip
        
[
            [0] {
                "hello" => "world"
            }
        ]
EOS end it 'encodes HTML entities (plain)' do markup = ' &' expect(markup.ai(html: true, plain: true)).to eq('
" &<hello>"
') end it 'encodes HTML entities (color)' do markup = ' &' expect(markup.ai(html: true)).to eq('
" &<hello>"
') end end #------------------------------------------------------------------------------ describe 'AwesomePrint.defaults' do after do AwesomePrint.defaults = nil end # See https://github.com/awesome-print/awesome_print/issues/98 it 'should properly merge the defaults' do AwesomePrint.defaults = { indent: -2, sort_keys: true } hash = { [0, 0, 255] => :yellow, :red => 'rgb(255, 0, 0)', 'magenta' => 'rgb(255, 0, 255)' } out = hash.ai(plain: true) expect(out).to eq <<-EOS.strip_heredoc.strip { [ 0, 0, 255 ] => :yellow, "magenta" => "rgb(255, 0, 255)", :red => "rgb(255, 0, 0)" } EOS end end #------------------------------------------------------------------------------ describe 'Coexistence with the colorize gem' do before do # Redefine String#red just like colorize gem does it. @awesome_method = ''.method(:red) String.instance_eval do define_method :red do # Method arity is now 0 in Ruby 1.9+. "[red]#{self}[/red]" end end end after do # Restore String#red method. awesome_method = @awesome_method String.instance_eval do define_method :red, awesome_method end end it 'shoud not raise ArgumentError when formatting HTML' do out = 'hello'.ai(color: { string: :red }, html: true) if RUBY_VERSION >= '1.9' expect(out).to eq(%Q|
[red]"hello"[/red]
|) else expect(out).to eq(%Q|
[red]"hello"[/red]
|) end end it 'shoud not raise ArgumentError when formatting HTML (shade color)' do out = 'hello'.ai(color: { string: :redish }, html: true) expect(out).to eq(%Q|
"hello"
|) end it 'shoud not raise ArgumentError when formatting non-HTML' do out = 'hello'.ai(color: { string: :red }, html: false) expect(out).to eq(%Q|[red]"hello"[/red]|) end it 'shoud not raise ArgumentError when formatting non-HTML (shade color)' do out = 'hello'.ai(color: { string: :redish }, html: false) expect(out).to eq(%Q|\e[0;31m"hello"\e[0m|) end end #------------------------------------------------------------------------------ describe 'Console' do it 'should detect IRB' do class IRB; end ENV.delete('RAILS_ENV') expect(AwesomePrint.console?).to eq(true) expect(AwesomePrint.rails_console?).to eq(false) Object.instance_eval { remove_const :IRB } end it 'should detect Pry' do class Pry; end ENV.delete('RAILS_ENV') expect(AwesomePrint.console?).to eq(true) expect(AwesomePrint.rails_console?).to eq(false) Object.instance_eval { remove_const :Pry } end it 'should detect Rails::Console' do class IRB; end module Rails; class Console; end; end expect(AwesomePrint.console?).to eq(true) expect(AwesomePrint.rails_console?).to eq(true) Object.instance_eval { remove_const :IRB } Object.instance_eval { remove_const :Rails } end it "should detect ENV['RAILS_ENV']" do class Pry; end ENV['RAILS_ENV'] = 'development' expect(AwesomePrint.console?).to eq(true) expect(AwesomePrint.rails_console?).to eq(true) Object.instance_eval { remove_const :Pry } end it 'should return the actual object when *not* running under console' do expect(capture! { ap([1, 2, 3]) }).to eq([1, 2, 3]) expect(capture! { ap({ a: 1 }) }).to eq({ a: 1 }) end it 'should return nil when running under console' do class IRB; end expect(capture! { ap([1, 2, 3]) }).to eq(nil) expect(capture! { ap({ a: 1 }) }).to eq(nil) Object.instance_eval { remove_const :IRB } end it 'handles NoMethodError on IRB implicit #ai' do module IRB; class Irb; end; end irb_context = double('irb_context', last_value: BasicObject.new) IRB.define_singleton_method :version, -> { 'test_version' } irb = IRB::Irb.new irb.instance_eval { @context = irb_context } AwesomePrint.irb! expect(irb).to receive(:puts).with("(Object doesn't support #ai)") expect { irb.output_value }.to_not raise_error Object.instance_eval { remove_const :IRB } end end end awesome_print-1.8.0/spec/ext/0000755000004100000410000000000013170662323016161 5ustar www-datawww-dataawesome_print-1.8.0/spec/ext/active_record_spec.rb0000644000004100000410000001670513170662323022342 0ustar www-datawww-datarequire 'spec_helper' require 'active_record_helper' RSpec.describe 'AwesomePrint/ActiveRecord', skip: -> { !ExtVerifier.has_rails? }.call do describe 'ActiveRecord instance, attributes only (default)' do before do ActiveRecord::Base.default_timezone = :utc @diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00') @laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00') @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true) end it 'display single record' do out = @ap.awesome(@diana) str = <<-EOS.strip # { :admin => false, :created_at => ?, :id => nil, :name => "Diana", :rank => 1 } EOS if RUBY_VERSION < '1.9' str.sub!('?', 'Sat Oct 10 12:30:00 UTC 1992') else str.sub!('?', '1992-10-10 12:30:00 UTC') end expect(out).to be_similar_to(str) end it 'display multiple records' do out = @ap.awesome([@diana, @laura]) str = <<-EOS.strip [ [0] # { :admin => false, :created_at => ??, :id => nil, :name => "Diana", :rank => 1 }, [1] # { :admin => true, :created_at => ?!, :id => nil, :name => "Laura", :rank => 2 } ] EOS if RUBY_VERSION < '1.9' str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992') str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003') else str.sub!('??', '1992-10-10 12:30:00 UTC') str.sub!('?!', '2003-05-26 14:15:00 UTC') end expect(out).to be_similar_to(str) end it 'display multiple records on a relation' do @diana.save @laura.save out = @ap.awesome(User.all) str = <<-EOS.strip [ [0] # { :admin => false, :created_at => ??, :id => 1, :name => "Diana", :rank => 1 }, [1] # { :admin => true, :created_at => ?!, :id => 2, :name => "Laura", :rank => 2 } ] EOS if RUBY_VERSION < '1.9' str.sub!('??', 'Sat Oct 10 12:30:00 UTC 1992') str.sub!('?!', 'Mon May 26 14:15:00 UTC 2003') else str.sub!('??', '1992-10-10 12:30:00 UTC') str.sub!('?!', '2003-05-26 14:15:00 UTC') end expect(out).to be_similar_to(str) end end describe 'Linked records (joins)' do before do @ap = AwesomePrint::Inspector.new(plain: true) end it 'should show the entire record' do e = Email.create(email_address: 'foo@bar.com') u = User.last u.emails << e email_record = User.joins(:emails).select('users.id, emails.email_address').last out = @ap.awesome(email_record) raw_object_string = <<-EOS.strip # { "id" => #{u.id}, "email_address" => "#{e.email_address}" } EOS expect(out).to be_similar_to(raw_object_string) end end #------------------------------------------------------------------------------ describe 'ActiveRecord instance (raw)' do before do ActiveRecord::Base.default_timezone = :utc @diana = User.new(name: 'Diana', rank: 1, admin: false, created_at: '1992-10-10 12:30:00') @laura = User.new(name: 'Laura', rank: 2, admin: true, created_at: '2003-05-26 14:15:00') @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true, raw: true) end it 'display single record' do out = @ap.awesome(@diana) raw_object_string = if activerecord_5_0? ActiveRecordData.raw_5_0_diana elsif activerecord_4_2? if RUBY_VERSION > '1.9.3' ActiveRecordData.raw_4_2_diana else ActiveRecordData.raw_4_2_diana_legacy end elsif activerecord_4_1? ActiveRecordData.raw_4_1_diana elsif activerecord_4_0? ActiveRecordData.raw_4_0_diana elsif activerecord_3_2? if RUBY_VERSION > '1.9.3' ActiveRecordData.raw_3_2_diana else ActiveRecordData.raw_3_2_diana_legacy end end raw_object_string.sub!('?', '1992-10-10 12:30:00') expect(out).to be_similar_to(raw_object_string) end it 'display multiple records' do out = @ap.awesome([@diana, @laura]) raw_object_string = if activerecord_5_0? ActiveRecordData.raw_5_0_multi elsif activerecord_4_2? if RUBY_VERSION > '1.9.3' ActiveRecordData.raw_4_2_multi else ActiveRecordData.raw_4_2_multi_legacy end elsif activerecord_4_1? ActiveRecordData.raw_4_1_multi elsif activerecord_4_0? ActiveRecordData.raw_4_0_multi elsif activerecord_3_2? if RUBY_VERSION > '1.9.3' ActiveRecordData.raw_3_2_multi else ActiveRecordData.raw_3_2_multi_legacy end end raw_object_string.sub!('?', '1992-10-10 12:30:00') raw_object_string.sub!('?', '2003-05-26 14:15:00') expect(out).to be_similar_to(raw_object_string) end end #------------------------------------------------------------------------------ describe 'ActiveRecord class' do before do @ap = AwesomePrint::Inspector.new(plain: true) end it 'should print the class' do expect(@ap.awesome(User)).to eq <<-EOS.strip class User < ActiveRecord::Base { :id => :integer, :name => :string, :rank => :integer, :admin => :boolean, :created_at => :datetime } EOS end it 'should print the class for non-direct subclasses of ActiveRecord::Base' do out = @ap.awesome(SubUser) expect(out).to eq <<-EOS.strip class SubUser < User { :id => :integer, :name => :string, :rank => :integer, :admin => :boolean, :created_at => :datetime } EOS end it 'should print ActiveRecord::Base objects (ex. ancestors)' do expect { @ap.awesome(User.ancestors) }.not_to raise_error end end #------------------------------------------------------------------------------ describe 'ActiveRecord methods formatting' do before do @ap = AwesomePrint::Inspector.new(plain: true) end it 'should format class methods properly' do # spec 1 out = @ap.awesome(User.methods.grep(/first/)) if ActiveRecord::VERSION::STRING >= '3.2' if RUBY_VERSION >= '1.9' expect(out).to match(/\sfirst\(\*args,\s&block\)\s+Class \(ActiveRecord::Querying\)/) else expect(out).to match(/\sfirst\(\*arg1\)\s+Class \(ActiveRecord::Querying\)/) end else expect(out).to match(/\sfirst\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/) end # spec 2 out = @ap.awesome(User.methods.grep(/primary_key/)) expect(out).to match(/\sprimary_key\(.*?\)\s+Class \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/) # spec 3 out = @ap.awesome(User.methods.grep(/validate/)) if ActiveRecord::VERSION::MAJOR < 3 expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/) else expect(out).to match(/\svalidate\(\*arg.*?\)\s+Class \(ActiveModel::Validations::ClassMethods\)/) end end end end awesome_print-1.8.0/spec/ext/nokogiri_spec.rb0000644000004100000410000000262613170662323021347 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint/Nokogiri' do it 'should colorize tags' do xml = Nokogiri::XML('

') expect(xml.ai).to eq <<-EOS \e[1;32m \e[0m<\e[1;36mhtml\e[0m>\e[1;32m \e[0m<\e[1;36mbody\e[0m>\e[1;32m \e[0m<\e[1;36mh1\e[0m/>\e[1;32m \e[0m<\e[1;36m/body\e[0m>\e[1;32m \e[0m<\e[1;36m/html\e[0m> EOS end it 'should colorize contents' do xml = Nokogiri::XML('

Hello

') expect(xml.ai).to eq <<-EOS \e[1;32m \e[0m<\e[1;36mhtml\e[0m>\e[1;32m \e[0m<\e[1;36mbody\e[0m>\e[1;32m \e[0m<\e[1;36mh1\e[0m>\e[1;32mHello\e[0m<\e[1;36m/h1\e[0m>\e[1;32m \e[0m<\e[1;36m/body\e[0m>\e[1;32m \e[0m<\e[1;36m/html\e[0m> EOS end it 'should colorize class and id' do xml = Nokogiri::XML('

') expect(xml.ai).to eq <<-EOS \e[1;32m \e[0m<\e[1;36mhtml\e[0m>\e[1;32m \e[0m<\e[1;36mbody\e[0m>\e[1;32m \e[0m<\e[1;36mh1\e[0m>\e[1;32m \e[0m<\e[1;36mspan\e[0m \e[1;33mid=\"hello\"\e[0m \e[1;33mclass=\"world\"\e[0m/>\e[1;32m \e[0m<\e[1;36m/h1\e[0m>\e[1;32m \e[0m<\e[1;36m/body\e[0m>\e[1;32m \e[0m<\e[1;36m/html\e[0m> EOS end it 'handle empty NodeSet' do xml = Nokogiri::XML::NodeSet.new(Nokogiri::XML('')) expect(xml.ai).to eq('[]') end end awesome_print-1.8.0/spec/ext/ripple_spec.rb0000644000004100000410000000207313170662323021015 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint/Ripple', skip: -> { !ExtVerifier.has_ripple? }.call do if ExtVerifier.has_ripple? before :all do class RippleUser include Ripple::Document key_on :_id property :_id, String property :first_name, String property :last_name, String end end after :all do Object.instance_eval { remove_const :RippleUser } end end before do @ap = AwesomePrint::Inspector.new plain: true, sort_keys: true end it 'should print class instance' do user = RippleUser.new _id: '12345', first_name: 'Al', last_name: 'Capone' out = @ap.send :awesome, user expect(out).to be_similar_to <<-EOS.strip # { :_id => "12345", :first_name => "Al", :last_name => "Capone" } EOS end it 'should print the class' do expect(@ap.send(:awesome, RippleUser)).to eq <<-EOS.strip class RippleUser < Object { :_id => :string, :first_name => :string, :last_name => :string } EOS end end awesome_print-1.8.0/spec/ext/mongoid_spec.rb0000644000004100000410000000502513170662323021156 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint/Mongoid', skip: -> { !ExtVerifier.has_mongoid? }.call do if ExtVerifier.has_mongoid? before :all do class MongoUser include Mongoid::Document field :first_name, type: String field :last_name, type: String end end after :all do Object.instance_eval { remove_const :MongoUser } Object.instance_eval { remove_const :Chamelion } end end before do @ap = AwesomePrint::Inspector.new plain: true, sort_keys: true end it 'should print class instance' do user = MongoUser.new first_name: 'Al', last_name: 'Capone' out = @ap.send :awesome, user object_id = user.id.inspect str = <<-EOS.strip # { :_id => #{object_id}, :first_name => "Al", :last_name => "Capone" } EOS expect(out).to be_similar_to(str, { skip_bson: true }) end it 'should print the class' do class_spec = if mongoid_3_0? <<-EOS.strip class MongoUser < Object { :_id => :"moped/bson/object_id", :_type => :string, :first_name => :string, :last_name => :string } EOS elsif mongoid_3_1? <<-EOS.strip class MongoUser < Object { :_id => :"moped/bson/object_id", :first_name => :string, :last_name => :string } EOS elsif mongoid_4_0? <<-EOS.strip class MongoUser < Object { :_id => :"bson/object_id", :first_name => :string, :last_name => :string } EOS end expect(@ap.send(:awesome, MongoUser)).to eq class_spec end it 'should print the class when type is undefined' do class Chamelion include Mongoid::Document field :last_attribute end class_spec = if mongoid_3_0? <<-EOS.strip class Chamelion < Object { :_id => :"moped/bson/object_id", :_type => :string, :last_attribute => :object } EOS elsif mongoid_3_1? <<-EOS.strip class Chamelion < Object { :_id => :"moped/bson/object_id", :last_attribute => :object } EOS elsif mongoid_4_0? <<-EOS.strip class Chamelion < Object { :_id => :"bson/object_id", :last_attribute => :object } EOS end expect(@ap.send(:awesome, Chamelion)).to eq class_spec end end awesome_print-1.8.0/spec/ext/nobrainer_spec.rb0000644000004100000410000000242613170662323021503 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint/NoBrainer', skip: -> { !ExtVerifier.has_nobrainer? }.call do if ExtVerifier.has_nobrainer? before :all do NoBrainer.configure do |config| config.app_name = 'ap_test' config.environment = :test end end before :all do class SomeModel include NoBrainer::Document field :first_name, type: String field :last_name, type: String field :some_field end end after :all do Object.instance_eval { remove_const :SomeModel } end end before do @ap = AwesomePrint::Inspector.new plain: true end it 'should print class instance' do user = SomeModel.new first_name: 'Al', last_name: 'Capone' out = @ap.send :awesome, user object_id = user.id.inspect str = <<-EOS.strip # { :id => #{object_id}, :first_name => "Al", :last_name => "Capone" } EOS expect(out).to eq(str) end it 'should print the class' do class_spec = <<-EOS.strip class SomeModel < Object { :id => :string, :first_name => :string, :last_name => :string, :some_field => :object } EOS expect(@ap.send(:awesome, SomeModel)).to eq class_spec end end awesome_print-1.8.0/spec/ext/ostruct_spec.rb0000644000004100000410000000076113170662323021227 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint Ostruct extension' do before do @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true) end it 'empty hash' do struct = OpenStruct.new expect(@ap.send(:awesome, struct)).to eq('OpenStruct {}') end it 'plain multiline' do struct = OpenStruct.new name: 'Foo', address: 'Bar' expect(@ap.send(:awesome, struct)).to eq <<-EOS.strip OpenStruct { :address => "Bar", :name => "Foo" } EOS end end awesome_print-1.8.0/spec/ext/action_view_spec.rb0000644000004100000410000000112413170662323022025 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint ActionView extensions', skip: -> { !ExtVerifier.has_rails? }.call do before do @view = ActionView::Base.new end it "uses HTML and adds 'debug_dump' class to plain
 tag" do
    markup = rand
    expect(@view.ap(markup, plain: true)).to eq(%Q|
#{markup}
|) end it "uses HTML and adds 'debug_dump' class to colorized
 tag" do
    markup = ' &'
    expect(@view.ap(markup)).to eq('
" &<hello>"
') end end awesome_print-1.8.0/spec/ext/active_support_spec.rb0000644000004100000410000000200413170662323022563 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint::ActiveSupport', skip: -> { !ExtVerifier.has_rails? }.call do before do @ap = AwesomePrint::Inspector.new end it 'should format ActiveSupport::TimeWithZone as regular Time' do Time.zone = 'Eastern Time (US & Canada)' time = Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone expect(@ap.send(:awesome, time)).to eq("\e[0;32mSat, 10 Feb 2007 15:30:45 EST -05:00\e[0m") end it 'should format HashWithIndifferentAccess as regular Hash' do hash = HashWithIndifferentAccess.new({ hello: 'world' }) expect(@ap.send(:awesome, hash)).to eq("{\n \"hello\"\e[0;37m => \e[0m\e[0;33m\"world\"\e[0m\n}") end # ActiveSupport sticks in instance variables to the date object. Make sure # we ignore that and format Date instance as regular date. it 'should formate Date object as date' do date = Date.new(2003, 5, 26) expect(date.ai(plain: true)).to eq('Mon, 26 May 2003') expect(date.ai).to eq("\e[0;32mMon, 26 May 2003\e[0m") end end awesome_print-1.8.0/spec/ext/mongo_mapper_spec.rb0000644000004100000410000001661713170662323022216 0ustar www-datawww-datarequire 'spec_helper' RSpec.describe 'AwesomePrint/MongoMapper', skip: -> { !ExtVerifier.has_mongo_mapper? }.call do if ExtVerifier.has_mongo_mapper? before :all do class MongoUser include MongoMapper::Document key :first_name, String key :last_name, String end end after :all do Object.instance_eval { remove_const :MongoUser } Object.instance_eval { remove_const :Chamelion } end end before do @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true) end describe 'with the raw option set to true' do # before { @ap.options[:raw] = true } before { @ap = AwesomePrint::Inspector.new(plain: true, sort_keys: true, raw: true) } it 'should print class instance' do user = MongoUser.new(first_name: 'Al', last_name: 'Capone') out = @ap.send(:awesome, user) out.gsub!(/#\/, 'AWESOME_PRINT_PROC_STUB') out.gsub!(/BSON::ObjectId\('[\da-f]+?'\)/, "BSON::ObjectId('123456789')") str = if MongoMapper::Version >= '0.13' <<-EOS.strip # AWESOME_PRINT_PROC_STUB }, attr_accessor :type = ObjectId < Object > ], @__mm_keys = { "_id" => # AWESOME_PRINT_PROC_STUB }, attr_accessor :type = ObjectId < Object >, "first_name" => #, "last_name" => # }, @__mm_pre_cast = { "first_name" => "Al", "last_name" => "Capone" }, @_dynamic_attributes = {}, @_new = true, attr_accessor :_id = BSON::ObjectId('123456789'), attr_accessor :attributes = nil, attr_accessor :first_name = "Al", attr_accessor :last_name = "Capone", attr_reader :changed_attributes = { "first_name" => nil, "last_name" => nil } > EOS else <<-EOS.strip # nil, "last_name" => nil }, attr_reader :first_name_before_type_cast = "Al", attr_reader :last_name_before_type_cast = "Capone" > EOS end expect(out).to be_similar_to(str) end it 'should print the class' do expect(@ap.send(:awesome, MongoUser)).to eq <<-EOS.strip class MongoUser < Object { "_id" => :object_id, "first_name" => :string, "last_name" => :string } EOS end it 'should print the class when type is undefined' do class Chamelion include MongoMapper::Document key :last_attribute end expect(@ap.send(:awesome, Chamelion)).to eq <<-EOS.strip class Chamelion < Object { "_id" => :object_id, "last_attribute" => :undefined } EOS end end describe 'with associations' do if ExtVerifier.has_mongo_mapper? before :all do class Child include MongoMapper::EmbeddedDocument key :data end class Sibling include MongoMapper::Document key :title end class Parent include MongoMapper::Document key :name one :child one :sibling end end end describe 'with show associations turned off (default)' do it 'should render the class as normal' do expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip class Parent < Object { "_id" => :object_id, "name" => :undefined } EOS end it 'should render an instance as normal' do parent = Parent.new(name: 'test') out = @ap.send(:awesome, parent) str = <<-EOS.strip # { "_id" => placeholder_bson_id, "name" => "test" } EOS expect(out).to be_similar_to(str) end end describe 'with show associations turned on and inline embedded turned off' do before :each do @ap = AwesomePrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true }) end it 'should render the class with associations shown' do expect(@ap.send(:awesome, Parent)).to eq <<-EOS.strip class Parent < Object { "_id" => :object_id, "name" => :undefined, "child" => embeds one Child, "sibling" => one Sibling } EOS end it 'should render an instance with associations shown' do parent = Parent.new(name: 'test') out = @ap.send(:awesome, parent) str = <<-EOS.strip # { "_id" => placeholder_bson_id, "name" => "test", "child" => embeds one Child, "sibling" => one Sibling } EOS expect(out).to be_similar_to(str) end end describe 'with show associations turned on and inline embedded turned on' do before :each do @ap = AwesomePrint::Inspector.new(plain: true, mongo_mapper: { show_associations: true, inline_embedded: true } ) end it 'should render an instance with associations shown and embeds there' do parent = Parent.new(name: 'test', child: Child.new(data: 5)) out = @ap.send(:awesome, parent) str = <<-EOS.strip # { "_id" => placeholder_bson_id, "name" => "test", "child" => embedded # { "_id" => placeholder_bson_id, "data" => 5 }, "sibling" => one Sibling } EOS expect(out).to be_similar_to(str) end end end end awesome_print-1.8.0/lib/0000755000004100000410000000000013170662323015175 5ustar www-datawww-dataawesome_print-1.8.0/lib/awesome_print.rb0000644000004100000410000000335313170662323020402 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ # # AwesomePrint might be loaded implicitly through ~/.irbrc or ~/.pryrc # so do nothing for subsequent requires. # unless defined?(AwesomePrint::Inspector) %w(awesome_method_array string method object class kernel).each do |file| require "awesome_print/core_ext/#{file}" end require 'awesome_print/custom_defaults' require 'awesome_print/inspector' require 'awesome_print/formatter' require 'awesome_print/version' require 'awesome_print/core_ext/logger' if defined?(Logger) # # Load the following under normal circumstances as well as in Rails # console when required from ~/.irbrc or ~/.pryrc. # require 'awesome_print/ext/active_record' if defined?(ActiveRecord) || AwesomePrint.rails_console? require 'awesome_print/ext/active_support' if defined?(ActiveSupport) || AwesomePrint.rails_console? # # Load remaining extensions. # if defined?(ActiveSupport.on_load) ActiveSupport.on_load(:action_view) do require 'awesome_print/ext/action_view' end end require 'awesome_print/ext/mongo_mapper' if defined?(MongoMapper) require 'awesome_print/ext/mongoid' if defined?(Mongoid) require 'awesome_print/ext/nokogiri' if defined?(Nokogiri) require 'awesome_print/ext/nobrainer' if defined?(NoBrainer) require 'awesome_print/ext/ripple' if defined?(Ripple) require 'awesome_print/ext/sequel' if defined?(Sequel) require 'awesome_print/ext/ostruct' if defined?(OpenStruct) end awesome_print-1.8.0/lib/ap.rb0000644000004100000410000000062713170662323016127 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ # # Keeping this for backwards compatibility to allow # require "ap" # require File.dirname(__FILE__) + '/awesome_print' awesome_print-1.8.0/lib/awesome_print/0000755000004100000410000000000013170662323020051 5ustar www-datawww-dataawesome_print-1.8.0/lib/awesome_print/formatter.rb0000644000004100000410000000671113170662323022406 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ require 'awesome_print/formatters' module AwesomePrint class Formatter include Colorize attr_reader :inspector, :options CORE = [:array, :bigdecimal, :class, :dir, :file, :hash, :method, :rational, :set, :struct, :unboundmethod] def initialize(inspector) @inspector = inspector @options = inspector.options end # Main entry point to format an object. #------------------------------------------------------------------------------ def format(object, type = nil) core_class = cast(object, type) awesome = if core_class != :self send(:"awesome_#{core_class}", object) # Core formatters. else awesome_self(object, type) # Catch all that falls back to object.inspect. end awesome end # Hook this when adding custom formatters. Check out lib/awesome_print/ext # directory for custom formatters that ship with awesome_print. #------------------------------------------------------------------------------ def cast(object, type) CORE.grep(type)[0] || :self end private # Catch all method to format an arbitrary object. #------------------------------------------------------------------------------ def awesome_self(object, type) if @options[:raw] && object.instance_variables.any? awesome_object(object) elsif (hash = convert_to_hash(object)) awesome_hash(hash) else awesome_simple(object.inspect.to_s, type, @inspector) end end def awesome_bigdecimal(n) o = n.to_s('F') type = :bigdecimal awesome_simple(o, type, @inspector) end def awesome_rational(n) o = n.to_s type = :rational awesome_simple(o, type, @inspector) end def awesome_simple(o, type, inspector = @inspector) AwesomePrint::Formatters::SimpleFormatter.new(o, type, inspector).format end def awesome_array(a) Formatters::ArrayFormatter.new(a, @inspector).format end def awesome_set(s) Formatters::ArrayFormatter.new(s.to_a, @inspector).format end def awesome_hash(h) Formatters::HashFormatter.new(h, @inspector).format end def awesome_object(o) Formatters::ObjectFormatter.new(o, @inspector).format end def awesome_struct(s) Formatters::StructFormatter.new(s, @inspector).format end def awesome_method(m) Formatters::MethodFormatter.new(m, @inspector).format end alias :awesome_unboundmethod :awesome_method def awesome_class(c) Formatters::ClassFormatter.new(c, @inspector).format end def awesome_file(f) Formatters::FileFormatter.new(f, @inspector).format end def awesome_dir(d) Formatters::DirFormatter.new(d, @inspector).format end # Utility methods. #------------------------------------------------------------------------------ def convert_to_hash(object) if !object.respond_to?(:to_hash) return nil end if object.method(:to_hash).arity != 0 return nil end hash = object.to_hash if !hash.respond_to?(:keys) || !hash.respond_to?('[]') return nil end return hash end end end awesome_print-1.8.0/lib/awesome_print/core_ext/0000755000004100000410000000000013170662323021661 5ustar www-datawww-dataawesome_print-1.8.0/lib/awesome_print/core_ext/string.rb0000644000004100000410000000205113170662323023512 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ class String # # ANSI color codes: # \e => escape # 30 => color base # 1 => bright # 0 => normal # # For HTML coloring we use tag instead of to require monospace # font. Note that beloved has been removed from HTML5. # %w(gray red green yellow blue purple cyan white).zip( %w(black darkred darkgreen brown navy darkmagenta darkcyan slategray)).each_with_index do |(color, shade), i| define_method color do |*html| html[0] ? %Q|#{self}| : "\e[1;#{30 + i}m#{self}\e[0m" end define_method "#{color}ish" do |*html| html[0] ? %Q|#{self}| : "\e[0;#{30 + i}m#{self}\e[0m" end end alias :black :grayish alias :pale :whiteish end awesome_print-1.8.0/lib/awesome_print/core_ext/class.rb0000644000004100000410000000163713170662323023322 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ class Class #:nodoc: # # Intercept methods below to inject @__awesome_print__ instance variable # so we know it is the *methods* array when formatting an array. # # Remaining public/private etc. '_methods' are handled in core_ext/object.rb. # %w(instance_methods private_instance_methods protected_instance_methods public_instance_methods).each do |name| original_method = instance_method(name) define_method name do |*args| methods = original_method.bind(self).call(*args) methods.instance_variable_set(:@__awesome_methods__, self) methods.extend(AwesomeMethodArray) methods end end end awesome_print-1.8.0/lib/awesome_print/core_ext/awesome_method_array.rb0000644000004100000410000000530513170662323026407 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ # # The following makes it possible to invoke awesome_print while performing # operations on method arrays, ex: # # ap [].methods - Object.methods # ap ''.methods.grep(/!|\?/) # # If you could think of a better way please let me know :-) # module AwesomeMethodArray #:nodoc: def -(_other_ary) super.tap do |arr| arr.instance_variable_set(:@__awesome_methods__, self.instance_variable_get(:@__awesome_methods__)) end end def &(_other_ary) super.tap do |arr| arr.instance_variable_set(:@__awesome_methods__, self.instance_variable_get(:@__awesome_methods__)) end end # # Intercepting Array#grep needs a special treatment since grep accepts # an optional block. # def grep(pattern, &blk) # # The following looks rather insane and I've sent numerous hours trying # to figure it out. The problem is that if grep gets called with the # block, for example: # # [].methods.grep(/(.+?)_by/) { $1.to_sym } # # ...then simple: # # original_grep(pattern, &blk) # # doesn't set $1 within the grep block which causes nil.to_sym failure. # The workaround below has been tested with Ruby 1.8.7/Rails 2.3.8 and # Ruby 1.9.2/Rails 3.0.0. For more info see the following thread dating # back to 2003 when Ruby 1.8.0 was as fresh off the grill as Ruby 1.9.2 # is in 2010 :-) # # http://www.justskins.com/forums/bug-when-rerouting-string-52852.html # # BTW, if you figure out a better way of intercepting Array#grep please # let me know: twitter.com/mid -- or just say hi so I know you've read # the comment :-) # arr = unless blk super(pattern) else super(pattern) do |match| # # The binding can only be used with Ruby-defined methods, therefore # we must rescue potential "ArgumentError: Can't create Binding from # C level Proc" error. # # For example, the following raises ArgumentError since #succ method # is defined in C. # # [ 0, 1, 2, 3, 4 ].grep(1..2, &:succ) # eval("%Q/#{match.to_s.gsub('/', '\/')}/ =~ #{pattern.inspect}", blk.binding) rescue ArgumentError yield match end end arr.instance_variable_set(:@__awesome_methods__, self.instance_variable_get(:@__awesome_methods__)) arr.reject! { |item| !(item.is_a?(Symbol) || item.is_a?(String)) } # grep block might return crap. arr end end awesome_print-1.8.0/lib/awesome_print/core_ext/logger.rb0000644000004100000410000000140013170662323023460 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module Logger # Add ap method to logger #------------------------------------------------------------------------------ def ap(object, level = nil) level ||= AwesomePrint.defaults[:log_level] if AwesomePrint.defaults level ||= :debug send level, object.ai end end end Logger.send(:include, AwesomePrint::Logger) ActiveSupport::BufferedLogger.send(:include, AwesomePrint::Logger) if defined?(ActiveSupport::BufferedLogger) awesome_print-1.8.0/lib/awesome_print/core_ext/object.rb0000644000004100000410000000160213170662323023453 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ class Object #:nodoc: # # Intercept methods below to inject @__awesome_print__ instance variable # so we know it is the *methods* array when formatting an array. # # Remaining instance '_methods' are handled in core_ext/class.rb. # %w(methods private_methods protected_methods public_methods singleton_methods).each do |name| original_method = instance_method(name) define_method name do |*args| methods = original_method.bind(self).call(*args) methods.instance_variable_set(:@__awesome_methods__, self) methods.extend(AwesomeMethodArray) methods end end end awesome_print-1.8.0/lib/awesome_print/core_ext/method.rb0000644000004100000410000000107713170662323023473 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ # # Method#name was intorduced in Ruby 1.8.7 so we define it here as necessary. # unless nil.method(:class).respond_to?(:name) class Method def name inspect.split(/[#.>]/)[-1] end end class UnboundMethod def name inspect.split(/[#.>]/)[-1] end end end awesome_print-1.8.0/lib/awesome_print/core_ext/kernel.rb0000644000004100000410000000134113170662323023465 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module Kernel def ai(options = {}) ap = AwesomePrint::Inspector.new(options) awesome = ap.awesome self if options[:html] awesome = "
#{awesome}
" awesome = awesome.html_safe if defined? ActiveSupport end awesome end alias :awesome_inspect :ai def ap(object, options = {}) puts object.ai(options) object unless AwesomePrint.console? end alias :awesome_print :ap module_function :ap end awesome_print-1.8.0/lib/awesome_print/indentator.rb0000644000004100000410000000050213170662323022542 0ustar www-datawww-datamodule AwesomePrint class Indentator attr_reader :shift_width, :indentation def initialize(indentation) @indentation = indentation @shift_width = indentation.freeze end def indent @indentation += shift_width yield ensure @indentation -= shift_width end end end awesome_print-1.8.0/lib/awesome_print/version.rb0000644000004100000410000000053313170662323022064 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint def self.version '1.8.0' end end awesome_print-1.8.0/lib/awesome_print/formatters/0000755000004100000410000000000013170662323022237 5ustar www-datawww-dataawesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb0000644000004100000410000000630613170662323025772 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class ArrayFormatter < BaseFormatter attr_reader :array, :inspector, :options def initialize(array, inspector) @array = array @inspector = inspector @options = inspector.options end def format if array.empty? '[]' elsif methods_array? methods_array else simple_array end end private def methods_array? array.instance_variable_defined?('@__awesome_methods__') end def simple_array if options[:multiline] multiline_array else '[ ' << array.map { |item| inspector.awesome(item) }.join(', ') << ' ]' end end def multiline_array data = unless should_be_limited? generate_printable_array else limited(generate_printable_array, width(array)) end %Q([\n#{data.join(",\n")}\n#{outdent}]) end def generate_printable_array array.map.with_index do |item, index| array_prefix(index, width(array)).tap do |temp| indented { temp << inspector.awesome(item) } end end end def array_prefix(iteration, width) generic_prefix(iteration, width) end def methods_array array.map!(&:to_s).sort! data = generate_printable_tuples.join("\n") "[\n#{data}\n#{outdent}]" end def generate_printable_tuples tuples.map.with_index do |item, index| tuple_prefix(index, width(tuples)).tap do |temp| indented { temp << tuple_template(item) } end end end def tuple_template(item) name_width, args_width = name_and_args_width [ colorize(item[0].rjust(name_width), :method), colorize(item[1].ljust(args_width), :args), ' ', colorize(item[2], :class) ].join end def tuples @tuples ||= array.map { |name| generate_tuple(name) } end def name_and_args_width name_and_args = tuples.transpose return name_and_args[0].map(&:size).max, name_and_args[1].map(&:size).max end def tuple_prefix(iteration, width) generic_prefix(iteration, width, ' ') end def generate_tuple(name) meth = case name when Symbol, String find_method(name) end meth ? method_tuple(meth) : [name.to_s, '(?)', '?'] end def find_method(name) object = array.instance_variable_get('@__awesome_methods__') meth = begin object.method(name) rescue NameError, ArgumentError nil end meth || begin object.instance_method(name) rescue NameError nil end end def generic_prefix(iteration, width, padding='') if options[:index] indent + colorize("[#{iteration.to_s.rjust(width)}] ", :array) else indent + padding end end def width(items) (items.size - 1).to_s.size end end end end awesome_print-1.8.0/lib/awesome_print/formatters/struct_formatter.rb0000644000004100000410000000357213170662323026202 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class StructFormatter < BaseFormatter attr_reader :struct, :variables, :inspector, :options def initialize(struct, inspector) @struct = struct @variables = struct.members @inspector = inspector @options = inspector.options end def format vars = variables.map do |var| property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet. accessor = if struct.respond_to?(:"#{property}=") struct.respond_to?(property) ? :accessor : :writer else struct.respond_to?(property) ? :reader : nil end if accessor ["attr_#{accessor} :#{property}", var] else [var.to_s, var] end end data = vars.sort.map do |declaration, var| key = left_aligned do align(declaration, declaration.size) end unless options[:plain] if key =~ /(@\w+)/ key.sub!($1, colorize($1, :variable)) else key.sub!(/(attr_\w+)\s(\:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}") end end indented do key << colorize(' = ', :hash) + inspector.awesome(struct.send(var)) end end if options[:multiline] "#<#{awesome_instance}\n#{data.join(%Q/,\n/)}\n#{outdent}>" else "#<#{awesome_instance} #{data.join(', ')}>" end end private def awesome_instance "#{struct.class.superclass}:#{struct.class}:0x%08x" % (struct.__id__ * 2) end def left_aligned current = options[:indent] options[:indent] = 0 yield ensure options[:indent] = current end end end end awesome_print-1.8.0/lib/awesome_print/formatters/class_formatter.rb0000644000004100000410000000103513170662323025753 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class ClassFormatter < BaseFormatter attr_reader :klass, :inspector, :options def initialize(klass, inspector) @klass = klass @inspector = inspector @options = inspector.options end def format superclass = klass.superclass if superclass colorize("#{klass.inspect} < #{superclass}", :class) else colorize(klass.inspect, :class) end end end end end awesome_print-1.8.0/lib/awesome_print/formatters/base_formatter.rb0000644000004100000410000001002513170662323025557 0ustar www-datawww-datarequire_relative '../colorize' module AwesomePrint module Formatters class BaseFormatter include Colorize DEFAULT_LIMIT_SIZE = 7 # To support limited output, for example: # # ap ('a'..'z').to_a, :limit => 3 # [ # [ 0] "a", # [ 1] .. [24], # [25] "z" # ] # # ap (1..100).to_a, :limit => true # Default limit is 7. # [ # [ 0] 1, # [ 1] 2, # [ 2] 3, # [ 3] .. [96], # [97] 98, # [98] 99, # [99] 100 # ] #------------------------------------------------------------------------------ def should_be_limited? options[:limit] or (options[:limit].is_a?(Integer) and options[:limit] > 0) end def get_limit_size case options[:limit] when true DEFAULT_LIMIT_SIZE else options[:limit] end end def limited(data, width, is_hash = false) limit = get_limit_size if data.length <= limit data else # Calculate how many elements to be displayed above and below the separator. head = limit / 2 tail = head - (limit - 1) % 2 # Add the proper elements to the temp array and format the separator. temp = data[0, head] + [nil] + data[-tail, tail] temp[head] = if is_hash "#{indent}#{data[head].strip} .. #{data[data.length - tail - 1].strip}" else "#{indent}[#{head.to_s.rjust(width)}] .. [#{data.length - tail - 1}]" end temp end end def method_tuple(method) if method.respond_to?(:parameters) # Ruby 1.9.2+ # See http://readruby.chengguangnan.com/methods#method-objects-parameters # (mirror: http://archive.is/XguCA#selection-3381.1-3381.11) args = method.parameters.inject([]) do |arr, (type, name)| name ||= (type == :block ? 'block' : "arg#{arr.size + 1}") arr << case type when :req then name.to_s when :opt, :rest then "*#{name}" when :block then "&#{name}" else '?' end end else # See http://ruby-doc.org/core/classes/Method.html#M001902 args = (1..method.arity.abs).map { |i| "arg#{i}" } args[-1] = "*#{args[-1]}" if method.arity < 0 end # method.to_s formats to handle: # # # # # # #)#_username> # # # # # # # if method.to_s =~ /(Unbound)*Method: (.*)[#\.]/ unbound = $1 && '(unbound)' klass = $2 if klass && klass =~ /(\(\w+:\s.*?\))/ # Is this ActiveRecord-style class? klass.sub!($1, '') # Yes, strip the fields leaving class name only. end owner = "#{klass}#{unbound}".gsub('(', ' (') end [method.name.to_s, "(#{args.join(', ')})", owner.to_s] end # # Indentation related methods #----------------------------------------- def indentation inspector.current_indentation end def indented inspector.increase_indentation(&Proc.new) end def indent ' ' * indentation end def outdent ' ' * (indentation - options[:indent].abs) end def align(value, width) if options[:multiline] if options[:indent] > 0 value.rjust(width) elsif options[:indent] == 0 indent + value.ljust(width) else indent[0, indentation + options[:indent]] + value.ljust(width) end else value end end end end end awesome_print-1.8.0/lib/awesome_print/formatters/file_formatter.rb0000644000004100000410000000105713170662323025571 0ustar www-datawww-datarequire_relative 'base_formatter' require 'shellwords' module AwesomePrint module Formatters class FileFormatter < BaseFormatter attr_reader :file, :inspector, :options def initialize(file, inspector) @file = file @inspector = inspector @options = inspector.options end def format ls = File.directory?(file) ? `ls -adlF #{file.path.shellescape}` : `ls -alF #{file.path.shellescape}` colorize(ls.empty? ? file.inspect : "#{file.inspect}\n#{ls.chop}", :file) end end end end awesome_print-1.8.0/lib/awesome_print/formatters/object_formatter.rb0000644000004100000410000000377613170662323026132 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class ObjectFormatter < BaseFormatter attr_reader :object, :variables, :inspector, :options def initialize(object, inspector) @object = object @variables = object.instance_variables @inspector = inspector @options = inspector.options end def format vars = variables.map do |var| property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet. accessor = if object.respond_to?(:"#{property}=") object.respond_to?(property) ? :accessor : :writer else object.respond_to?(property) ? :reader : nil end if accessor ["attr_#{accessor} :#{property}", var] else [var.to_s, var] end end data = (options[:sort_vars] ? vars.sort : vars).map do |declaration, var| key = left_aligned do align(declaration, declaration.size) end unless options[:plain] if key =~ /(@\w+)/ key.sub!($1, colorize($1, :variable)) else key.sub!(/(attr_\w+)\s(\:\w+)/, "#{colorize('\\1', :keyword)} #{colorize('\\2', :method)}") end end indented do key << colorize(' = ', :hash) + inspector.awesome(object.instance_variable_get(var)) end end if options[:multiline] "#<#{awesome_instance}\n#{data.join(%Q/,\n/)}\n#{outdent}>" else "#<#{awesome_instance} #{data.join(', ')}>" end end private def valid_instance_var?(variable_name) variable_name.to_s.start_with?('@') end def awesome_instance "#{object.class}:0x%08x" % (object.__id__ * 2) end def left_aligned current = options[:indent] options[:indent] = 0 yield ensure options[:indent] = current end end end end awesome_print-1.8.0/lib/awesome_print/formatters/dir_formatter.rb0000644000004100000410000000075013170662323025427 0ustar www-datawww-datarequire_relative 'base_formatter' require 'shellwords' module AwesomePrint module Formatters class DirFormatter < BaseFormatter attr_reader :dir, :inspector, :options def initialize(dir, inspector) @dir = dir @inspector = inspector @options = inspector.options end def format ls = `ls -alF #{dir.path.shellescape}` colorize(ls.empty? ? dir.inspect : "#{dir.inspect}\n#{ls.chop}", :dir) end end end end awesome_print-1.8.0/lib/awesome_print/formatters/method_formatter.rb0000644000004100000410000000075613170662323026137 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class MethodFormatter < BaseFormatter attr_reader :method, :inspector, :options def initialize(method, inspector) @method = method @inspector = inspector @options = inspector.options end def format name, args, owner = method_tuple(method) "#{colorize(owner, :class)}##{colorize(name, :method)}#{colorize(args, :args)}" end end end end awesome_print-1.8.0/lib/awesome_print/formatters/simple_formatter.rb0000644000004100000410000000064513170662323026145 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class SimpleFormatter < BaseFormatter attr_reader :string, :type, :inspector, :options def initialize(string, type, inspector) @string = string @type = type @inspector = inspector @options = inspector.options end def format colorize(string, type) end end end end awesome_print-1.8.0/lib/awesome_print/formatters/hash_formatter.rb0000644000004100000410000000447213170662323025601 0ustar www-datawww-datarequire_relative 'base_formatter' module AwesomePrint module Formatters class HashFormatter < BaseFormatter attr_reader :hash, :inspector, :options def initialize(hash, inspector) @hash = hash @inspector = inspector @options = inspector.options end def format if hash.empty? empty_hash elsif multiline_hash? multiline_hash else simple_hash end end private def empty_hash '{}' end def multiline_hash? options[:multiline] end def multiline_hash "{\n" << printable_hash.join(",\n") << "\n#{outdent}}" end def simple_hash "{ #{printable_hash.join(', ')} }" end def printable_hash data = printable_keys width = left_width(data) data.map! do |key, value| indented do if options[:ruby19_syntax] && symbol?(key) ruby19_syntax(key, value, width) else pre_ruby19_syntax(key, value, width) end end end should_be_limited? ? limited(data, width, hash: true) : data end def left_width(keys) result = max_key_width(keys) result += indentation if options[:indent] > 0 result end def max_key_width(keys) keys.map { |key, _value| key.size }.max || 0 end def printable_keys keys = hash.keys keys.sort! { |a, b| a.to_s <=> b.to_s } if options[:sort_keys] keys.map! do |key| plain_single_line do [inspector.awesome(key), hash[key]] end end end def symbol?(key) key[0] == ':' end def ruby19_syntax(key, value, width) key[0] = '' align(key, width - 1) << colorize(': ', :hash) << inspector.awesome(value) end def pre_ruby19_syntax(key, value, width) align(key, width) << colorize(' => ', :hash) << inspector.awesome(value) end def plain_single_line plain = options[:plain] multiline = options[:multiline] options[:plain] = true options[:multiline] = false yield ensure options[:plain] = plain options[:multiline] = multiline end end end end awesome_print-1.8.0/lib/awesome_print/colorize.rb0000644000004100000410000000154113170662323022225 0ustar www-datawww-dataautoload :CGI, 'cgi' module AwesomePrint module Colorize # Pick the color and apply it to the given string as necessary. #------------------------------------------------------------------------------ def colorize(str, type) str = CGI.escapeHTML(str) if options[:html] if options[:plain] || !options[:color][type] || !inspector.colorize? str # # Check if the string color method is defined by awesome_print and accepts # html parameter or it has been overriden by some gem such as colorize. # elsif str.method(options[:color][type]).arity == -1 # Accepts html parameter. str.send(options[:color][type], options[:html]) else str = %Q|#{str}| if options[:html] str.send(options[:color][type]) end end end end awesome_print-1.8.0/lib/awesome_print/formatters.rb0000644000004100000410000000110713170662323022563 0ustar www-datawww-datamodule 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' end end awesome_print-1.8.0/lib/awesome_print/inspector.rb0000644000004100000410000001262013170662323022405 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ require_relative 'indentator' module AwesomePrint class Inspector attr_accessor :options, :indentator AP = :__awesome_print__ def initialize(options = {}) @options = { indent: 4, # Number of spaces for indenting. index: true, # Display array indices. html: false, # Use ANSI color codes rather than HTML. multiline: true, # Display in multiple lines. plain: false, # Use colors. raw: false, # Do not recursively format instance variables. sort_keys: false, # Do not sort hash keys. sort_vars: true, # Sort instance variables. limit: false, # Limit arrays & hashes. Accepts bool or int. ruby19_syntax: false, # Use Ruby 1.9 hash syntax in output. color: { args: :pale, array: :white, bigdecimal: :blue, class: :yellow, date: :greenish, falseclass: :red, fixnum: :blue, float: :blue, hash: :pale, keyword: :cyan, method: :purpleish, nilclass: :red, rational: :blue, string: :yellowish, struct: :pale, symbol: :cyanish, time: :greenish, trueclass: :green, variable: :cyanish } } # Merge custom defaults and let explicit options parameter override them. merge_custom_defaults! merge_options!(options) @formatter = AwesomePrint::Formatter.new(self) @indentator = AwesomePrint::Indentator.new(@options[:indent].abs) Thread.current[AP] ||= [] end def current_indentation indentator.indentation end def increase_indentation indentator.indent(&Proc.new) end # Dispatcher that detects data nesting and invokes object-aware formatter. #--------------------------------------------------------------------------- def awesome(object) if Thread.current[AP].include?(object.object_id) nested(object) else begin Thread.current[AP] << object.object_id unnested(object) ensure Thread.current[AP].pop end end end # Return true if we are to colorize the output. #--------------------------------------------------------------------------- def colorize? AwesomePrint.force_colors ||= false AwesomePrint.force_colors || ( STDOUT.tty? && ( ( ENV['TERM'] && ENV['TERM'] != 'dumb' ) || ENV['ANSICON'] ) ) end private # Format nested data, for example: # arr = [1, 2]; arr << arr # => [1,2, [...]] # hash = { :a => 1 }; hash[:b] = hash # => { :a => 1, :b => {...} } #--------------------------------------------------------------------------- def nested(object) case printable(object) when :array then @formatter.colorize('[...]', :array) when :hash then @formatter.colorize('{...}', :hash) when :struct then @formatter.colorize('{...}', :struct) else @formatter.colorize("...#{object.class}...", :class) end end #--------------------------------------------------------------------------- def unnested(object) @formatter.format(object, printable(object)) end # Turn class name into symbol, ex: Hello::World => :hello_world. Classes # that inherit from Array, Hash, File, Dir, and Struct are treated as the # base class. #--------------------------------------------------------------------------- def printable(object) case object when Array then :array when Hash then :hash when File then :file when Dir then :dir when Struct then :struct else object.class.to_s.gsub(/:+/, '_').downcase.to_sym end end # Update @options by first merging the :color hash and then the remaining # keys. #--------------------------------------------------------------------------- def merge_options!(options = {}) @options[:color].merge!(options.delete(:color) || {}) @options.merge!(options) end # This method needs to be mocked during testing so that it always loads # predictable values #--------------------------------------------------------------------------- def load_dotfile dotfile = File.join(ENV['HOME'], '.aprc') load dotfile if dotfile_readable?(dotfile) end def dotfile_readable? dotfile if @@dotfile_readable.nil? || @@dotfile != dotfile @@dotfile_readable = File.readable?(@@dotfile = dotfile) end @@dotfile_readable end @@dotfile_readable = @@dotfile = nil # Load ~/.aprc file with custom defaults that override default options. #--------------------------------------------------------------------------- def merge_custom_defaults! load_dotfile merge_options!(AwesomePrint.defaults) if AwesomePrint.defaults.is_a?(Hash) rescue => e $stderr.puts "Could not load #{dotfile}: #{e}" end end end awesome_print-1.8.0/lib/awesome_print/custom_defaults.rb0000644000004100000410000000252513170662323023603 0ustar www-datawww-datamodule 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)) end def rails_console? console? && boolean(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 private # Takes a value and returns true unless it is false or nil # This is an alternative to the less readable !!(value) # https://github.com/bbatsov/ruby-style-guide#no-bang-bang def boolean(value) value ? true : false end end end awesome_print-1.8.0/lib/awesome_print/ext/0000755000004100000410000000000013170662323020651 5ustar www-datawww-dataawesome_print-1.8.0/lib/awesome_print/ext/active_record.rb0000644000004100000410000000603713170662323024015 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module ActiveRecord def self.included(base) base.send :alias_method, :cast_without_active_record, :cast base.send :alias_method, :cast, :cast_with_active_record end # Add ActiveRecord class names to the dispatcher pipeline. #------------------------------------------------------------------------------ def cast_with_active_record(object, type) cast = cast_without_active_record(object, type) return cast if !defined?(::ActiveRecord::Base) if object.is_a?(::ActiveRecord::Base) cast = :active_record_instance elsif object.is_a?(Class) && object.ancestors.include?(::ActiveRecord::Base) cast = :active_record_class elsif type == :activerecord_relation || object.class.ancestors.include?(::ActiveRecord::Relation) cast = :array end cast end private # Format ActiveRecord instance object. # # NOTE: by default only instance attributes (i.e. columns) are shown. To format # ActiveRecord instance as regular object showing its instance variables and # accessors use :raw => true option: # # ap record, :raw => true # #------------------------------------------------------------------------------ def awesome_active_record_instance(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] data = if object.class.column_names != object.attributes.keys object.attributes else object.class.column_names.inject(::ActiveSupport::OrderedHash.new) do |hash, name| if object.has_attribute?(name) || object.new_record? value = object.respond_to?(name) ? object.send(name) : object.read_attribute(name) hash[name.to_sym] = value end hash end end "#{object} " << awesome_hash(data) end # Format ActiveRecord class object. #------------------------------------------------------------------------------ def awesome_active_record_class(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:columns) || object.to_s == 'ActiveRecord::Base' return awesome_class(object) if object.respond_to?(:abstract_class?) && object.abstract_class? data = object.columns.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c.name.to_sym] = c.type hash end name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end end end AwesomePrint::Formatter.send(:include, AwesomePrint::ActiveRecord) awesome_print-1.8.0/lib/awesome_print/ext/sequel.rb0000644000004100000410000000436613170662323022505 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module Sequel def self.included(base) base.send :alias_method, :cast_without_sequel, :cast base.send :alias_method, :cast, :cast_with_sequel end # Add Sequel class names to the dispatcher pipeline. #------------------------------------------------------------------------------ def cast_with_sequel(object, type) cast = cast_without_sequel(object, type) if defined?(::Sequel::Model) && object.is_a?(::Sequel::Model) cast = :sequel_document elsif defined?(::Sequel::Model) && object.is_a?(Class) && object.ancestors.include?(::Sequel::Model) cast = :sequel_model_class elsif defined?(::Sequel::Mysql2::Dataset) && object.class.ancestors.include?(::Sequel::Mysql2::Dataset) cast = :sequel_dataset end cast end # Format Sequel Document object. #------------------------------------------------------------------------------ def awesome_sequel_document(object) data = object.values.sort_by { |key| key.to_s }.inject({}) do |hash, c| hash[c[0].to_sym] = c[1] hash end data = { errors: object.errors, values: data } if !object.errors.empty? "#{object} #{awesome_hash(data)}" end # Format Sequel Dataset object. #------------------------------------------------------------------------------ def awesome_sequel_dataset(dataset) [awesome_array(dataset.to_a), awesome_print(dataset.sql)].join("\n") end # Format Sequel Model class. #------------------------------------------------------------------------------ def awesome_sequel_model_class(object) data = object.db_schema.inject({}) { |h, (prop, defn)| h.merge(prop => defn[:db_type]) } name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end end end AwesomePrint::Formatter.send(:include, AwesomePrint::Sequel) awesome_print-1.8.0/lib/awesome_print/ext/ostruct.rb0000644000004100000410000000157313170662323022707 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module OpenStruct def self.included(base) base.send :alias_method, :cast_without_ostruct, :cast base.send :alias_method, :cast, :cast_with_ostruct end def cast_with_ostruct(object, type) cast = cast_without_ostruct(object, type) if (defined?(::OpenStruct)) && (object.is_a?(::OpenStruct)) cast = :open_struct_instance end cast end def awesome_open_struct_instance(object) "#{object.class} #{awesome_hash(object.marshal_dump)}" end end end AwesomePrint::Formatter.send(:include, AwesomePrint::OpenStruct) awesome_print-1.8.0/lib/awesome_print/ext/ripple.rb0000644000004100000410000000526113170662323022475 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module Ripple def self.included(base) base.send :alias_method, :cast_without_ripple, :cast base.send :alias_method, :cast, :cast_with_ripple end # Add Ripple class names to the dispatcher pipeline. #------------------------------------------------------------------------------ def cast_with_ripple(object, type) cast = cast_without_ripple(object, type) return cast if !defined?(::Ripple) if object.is_a?(::Ripple::AttributeMethods) # Module used to access attributes across documents and embedded documents cast = :ripple_document_instance elsif object.is_a?(::Ripple::Properties) # Used to access property metadata on Ripple classes cast = :ripple_document_class end cast end private # Format Ripple instance object. # # NOTE: by default only instance attributes are shown. To format a Ripple document instance # as a regular object showing its instance variables and accessors use :raw => true option: # # ap document, :raw => true # #------------------------------------------------------------------------------ def awesome_ripple_document_instance(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] exclude_assoc = @options[:exclude_assoc] or @options[:exclude_associations] data = object.attributes.inject(::ActiveSupport::OrderedHash.new) do |hash, (name, value)| hash[name.to_sym] = object.send(name) hash end unless exclude_assoc data = object.class.embedded_associations.inject(data) do |hash, assoc| hash[assoc.name] = object.get_proxy(assoc) # Should always be array or Ripple::EmbeddedDocument for embedded associations hash end end "#{object} " << awesome_hash(data) end # Format Ripple class object. #------------------------------------------------------------------------------ def awesome_ripple_document_class(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties) name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end end end AwesomePrint::Formatter.send(:include, AwesomePrint::Ripple) awesome_print-1.8.0/lib/awesome_print/ext/mongo_mapper.rb0000644000004100000410000001111713170662323023662 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module MongoMapper def self.included(base) base.send :alias_method, :cast_without_mongo_mapper, :cast base.send :alias_method, :cast, :cast_with_mongo_mapper end # Add MongoMapper class names to the dispatcher pipeline. #------------------------------------------------------------------------------ def cast_with_mongo_mapper(object, type) apply_default_mongo_mapper_options cast = cast_without_mongo_mapper(object, type) if defined?(::MongoMapper::Document) if object.is_a?(Class) && (object.ancestors & [::MongoMapper::Document, ::MongoMapper::EmbeddedDocument]).size > 0 cast = :mongo_mapper_class elsif object.is_a?(::MongoMapper::Document) || object.is_a?(::MongoMapper::EmbeddedDocument) cast = :mongo_mapper_instance elsif object.is_a?(::MongoMapper::Plugins::Associations::Base) cast = :mongo_mapper_association elsif object.is_a?(::BSON::ObjectId) cast = :mongo_mapper_bson_id end end cast end # Format MongoMapper class object. #------------------------------------------------------------------------------ def awesome_mongo_mapper_class(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys) data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c.first] = (c.last.type || 'undefined').to_s.underscore.intern hash end # Add in associations if @options[:mongo_mapper][:show_associations] object.associations.each do |name, assoc| data[name.to_s] = assoc end end name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end # Format MongoMapper instance object. # # NOTE: by default only instance attributes (i.e. keys) are shown. To format # MongoMapper instance as regular object showing its instance variables and # accessors use :raw => true option: # # ap record, :raw => true # #------------------------------------------------------------------------------ def awesome_mongo_mapper_instance(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] data = object.keys.keys.sort_by { |k| k }.inject(::ActiveSupport::OrderedHash.new) do |hash, name| hash[name] = object[name] hash end # Add in associations if @options[:mongo_mapper][:show_associations] object.associations.each do |name, assoc| data[name.to_s] = if @options[:mongo_mapper][:inline_embedded] and assoc.embeddable? object.send(name) else assoc end end end label = object.to_s label = "#{colorize('embedded', :assoc)} #{label}" if object.is_a?(::MongoMapper::EmbeddedDocument) "#{label} " << awesome_hash(data) end # Format MongoMapper association object. #------------------------------------------------------------------------------ def awesome_mongo_mapper_association(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] association = object.class.name.split('::').last.titleize.downcase.sub(/ association$/, '') association = "embeds #{association}" if object.embeddable? class_name = object.class_name "#{colorize(association, :assoc)} #{colorize(class_name, :class)}" end # Format BSON::ObjectId #------------------------------------------------------------------------------ def awesome_mongo_mapper_bson_id(object) object.inspect end private def apply_default_mongo_mapper_options @options[:color][:assoc] ||= :greenish @options[:mongo_mapper] ||= { show_associations: false, # Display association data for MongoMapper documents and classes. inline_embedded: false # Display embedded associations inline with MongoMapper documents. } end end end AwesomePrint::Formatter.send(:include, AwesomePrint::MongoMapper) awesome_print-1.8.0/lib/awesome_print/ext/mongoid.rb0000644000004100000410000000507713170662323022643 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module Mongoid def self.included(base) base.send :alias_method, :cast_without_mongoid, :cast base.send :alias_method, :cast, :cast_with_mongoid end # Add Mongoid class names to the dispatcher pipeline. #------------------------------------------------------------------------------ def cast_with_mongoid(object, type) cast = cast_without_mongoid(object, type) if defined?(::Mongoid::Document) if object.is_a?(Class) && object.ancestors.include?(::Mongoid::Document) cast = :mongoid_class elsif object.class.ancestors.include?(::Mongoid::Document) cast = :mongoid_document elsif (defined?(::BSON) && object.is_a?(::BSON::ObjectId)) || (defined?(::Moped::BSON) && object.is_a?(::Moped::BSON::ObjectId)) cast = :mongoid_bson_id end end cast end # Format Mongoid class object. #------------------------------------------------------------------------------ def awesome_mongoid_class(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:fields) data = object.fields.sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c[1].name.to_sym] = (c[1].type || 'undefined').to_s.underscore.intern hash end name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end # Format Mongoid Document object. #------------------------------------------------------------------------------ def awesome_mongoid_document(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) data = (object.attributes || {}).sort_by { |key| key }.inject(::ActiveSupport::OrderedHash.new) do |hash, c| hash[c[0].to_sym] = c[1] hash end data = { errors: object.errors, attributes: data } if !object.errors.empty? "#{object} #{awesome_hash(data)}" end # Format BSON::ObjectId #------------------------------------------------------------------------------ def awesome_mongoid_bson_id(object) object.inspect end end end AwesomePrint::Formatter.send(:include, AwesomePrint::Mongoid) awesome_print-1.8.0/lib/awesome_print/ext/action_view.rb0000644000004100000410000000124613170662323023510 0ustar www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors # # Awesome Print is freely distributable under the terms of MIT license. # See LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ module AwesomePrint module ActionView # Use HTML colors and add default "debug_dump" class to the resulting HTML. def ap_debug(object, options = {}) object.ai( options.merge(html: true) ).sub( /^])/, '
([^<]+)#{contents}<"
      end
      xml
    end
  end
end

AwesomePrint::Formatter.send(:include, AwesomePrint::Nokogiri)
awesome_print-1.8.0/lib/awesome_print/ext/active_support.rb0000644000004100000410000000321213170662323024243 0ustar  www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
module AwesomePrint
  module ActiveSupport

    def self.included(base)
      base.send :alias_method, :cast_without_active_support, :cast
      base.send :alias_method, :cast, :cast_with_active_support
    end

    def cast_with_active_support(object, type)
      cast = cast_without_active_support(object, type)
      if defined?(::ActiveSupport) && defined?(::HashWithIndifferentAccess)
        if (defined?(::ActiveSupport::TimeWithZone) && object.is_a?(::ActiveSupport::TimeWithZone)) || object.is_a?(::Date)
          cast = :active_support_time
        elsif object.is_a?(::HashWithIndifferentAccess)
          cast = :hash_with_indifferent_access
        end
      end
      cast
    end

    # Format ActiveSupport::TimeWithZone as standard Time.
    #------------------------------------------------------------------------------
    def awesome_active_support_time(object)
      colorize(object.inspect, :time)
    end

    # Format HashWithIndifferentAccess as standard Hash.
    #------------------------------------------------------------------------------
    def awesome_hash_with_indifferent_access(object)
      awesome_hash(object)
    end
  end
end

AwesomePrint::Formatter.send(:include, AwesomePrint::ActiveSupport)
#
# Colorize Rails logs.
#
if defined?(ActiveSupport::LogSubscriber)
  AwesomePrint.force_colors! ActiveSupport::LogSubscriber.colorize_logging
end

awesome_print-1.8.0/lib/awesome_print/ext/nobrainer.rb0000644000004100000410000000371613170662323023164 0ustar  www-datawww-data# Copyright (c) 2010-2016 Michael Dvorkin and contributors
#
# Awesome Print is freely distributable under the terms of MIT license.
# See LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
module AwesomePrint
  module NoBrainer

    def self.included(base)
      base.send :alias_method, :cast_without_nobrainer, :cast
      base.send :alias_method, :cast, :cast_with_nobrainer
    end

    # Add NoBrainer class names to the dispatcher pipeline.
    #------------------------------------------------------------------------------
    def cast_with_nobrainer(object, type)
      cast = cast_without_nobrainer(object, type)
      if defined?(::NoBrainer::Document)
        if object.is_a?(Class) && object < ::NoBrainer::Document
          cast = :nobrainer_class
        elsif object.is_a?(::NoBrainer::Document)
          cast = :nobrainer_document
        end
      end
      cast
    end

    # Format NoBrainer class object.
    #------------------------------------------------------------------------------
    def awesome_nobrainer_class(object)
      name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}"
      data = Hash[object.fields.map do |field, options|
        [field, (options[:type] || Object).to_s.underscore.to_sym]
      end]

      name = "class #{awesome_simple(object.to_s, :class)}"
      base = "< #{awesome_simple(object.superclass.to_s, :class)}"

      [name, base, awesome_hash(data)].join(' ')
    end

    # Format NoBrainer Document object.
    #------------------------------------------------------------------------------
    def awesome_nobrainer_document(object)
      data = object.inspectable_attributes.symbolize_keys
      data = { errors: object.errors, attributes: data } if object.errors.present?
      "#{object} #{awesome_hash(data)}"
    end
  end
end

AwesomePrint::Formatter.send(:include, AwesomePrint::NoBrainer)
awesome_print-1.8.0/awesome_print.gemspec0000644000004100000410000001464513170662323020662 0ustar  www-datawww-data#########################################################
# This file has been automatically generated by gem2tgz #
#########################################################
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
  s.name = "awesome_print"
  s.version = "1.8.0"

  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
  s.authors = ["Michael Dvorkin"]
  s.date = "2017-06-16"
  s.description = "Great Ruby dubugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins"
  s.email = "mike@dvorkin.net"
  s.files = [".gitignore", "Appraisals", "CHANGELOG.md", "CONTRIBUTING.md", "Gemfile", "Gemfile.lock", "LICENSE", "README.md", "Rakefile", "lib/ap.rb", "lib/awesome_print.rb", "lib/awesome_print/colorize.rb", "lib/awesome_print/core_ext/awesome_method_array.rb", "lib/awesome_print/core_ext/class.rb", "lib/awesome_print/core_ext/kernel.rb", "lib/awesome_print/core_ext/logger.rb", "lib/awesome_print/core_ext/method.rb", "lib/awesome_print/core_ext/object.rb", "lib/awesome_print/core_ext/string.rb", "lib/awesome_print/custom_defaults.rb", "lib/awesome_print/ext/action_view.rb", "lib/awesome_print/ext/active_record.rb", "lib/awesome_print/ext/active_support.rb", "lib/awesome_print/ext/mongo_mapper.rb", "lib/awesome_print/ext/mongoid.rb", "lib/awesome_print/ext/nobrainer.rb", "lib/awesome_print/ext/nokogiri.rb", "lib/awesome_print/ext/ostruct.rb", "lib/awesome_print/ext/ripple.rb", "lib/awesome_print/ext/sequel.rb", "lib/awesome_print/formatter.rb", "lib/awesome_print/formatters.rb", "lib/awesome_print/formatters/array_formatter.rb", "lib/awesome_print/formatters/base_formatter.rb", "lib/awesome_print/formatters/class_formatter.rb", "lib/awesome_print/formatters/dir_formatter.rb", "lib/awesome_print/formatters/file_formatter.rb", "lib/awesome_print/formatters/hash_formatter.rb", "lib/awesome_print/formatters/method_formatter.rb", "lib/awesome_print/formatters/object_formatter.rb", "lib/awesome_print/formatters/simple_formatter.rb", "lib/awesome_print/formatters/struct_formatter.rb", "lib/awesome_print/indentator.rb", "lib/awesome_print/inspector.rb", "lib/awesome_print/version.rb", "spec/active_record_helper.rb", "spec/colors_spec.rb", "spec/core_ext/logger_spec.rb", "spec/core_ext/string_spec.rb", "spec/ext/action_view_spec.rb", "spec/ext/active_record_spec.rb", "spec/ext/active_support_spec.rb", "spec/ext/mongo_mapper_spec.rb", "spec/ext/mongoid_spec.rb", "spec/ext/nobrainer_spec.rb", "spec/ext/nokogiri_spec.rb", "spec/ext/ostruct_spec.rb", "spec/ext/ripple_spec.rb", "spec/formats_spec.rb", "spec/methods_spec.rb", "spec/misc_spec.rb", "spec/objects_spec.rb", "spec/spec_helper.rb", "spec/support/active_record_data.rb", "spec/support/active_record_data/3_2_diana.txt", "spec/support/active_record_data/3_2_diana_legacy.txt", "spec/support/active_record_data/3_2_multi.txt", "spec/support/active_record_data/3_2_multi_legacy.txt", "spec/support/active_record_data/4_0_diana.txt", "spec/support/active_record_data/4_0_multi.txt", "spec/support/active_record_data/4_1_diana.txt", "spec/support/active_record_data/4_1_multi.txt", "spec/support/active_record_data/4_2_diana.txt", "spec/support/active_record_data/4_2_diana_legacy.txt", "spec/support/active_record_data/4_2_multi.txt", "spec/support/active_record_data/4_2_multi_legacy.txt", "spec/support/active_record_data/5_0_diana.txt", "spec/support/active_record_data/5_0_multi.txt", "spec/support/ext_verifier.rb", "spec/support/mongoid_versions.rb", "spec/support/rails_versions.rb"]
  s.homepage = "https://github.com/awesome-print/awesome_print"
  s.licenses = ["MIT"]
  s.require_paths = ["lib"]
  s.rubyforge_project = "awesome_print"
  s.rubygems_version = "1.8.23"
  s.summary = "Pretty print Ruby objects with proper indentation and colors"
  s.test_files = ["spec/active_record_helper.rb", "spec/colors_spec.rb", "spec/core_ext/logger_spec.rb", "spec/core_ext/string_spec.rb", "spec/ext/action_view_spec.rb", "spec/ext/active_record_spec.rb", "spec/ext/active_support_spec.rb", "spec/ext/mongo_mapper_spec.rb", "spec/ext/mongoid_spec.rb", "spec/ext/nobrainer_spec.rb", "spec/ext/nokogiri_spec.rb", "spec/ext/ostruct_spec.rb", "spec/ext/ripple_spec.rb", "spec/formats_spec.rb", "spec/methods_spec.rb", "spec/misc_spec.rb", "spec/objects_spec.rb", "spec/spec_helper.rb", "spec/support/active_record_data.rb", "spec/support/active_record_data/3_2_diana.txt", "spec/support/active_record_data/3_2_diana_legacy.txt", "spec/support/active_record_data/3_2_multi.txt", "spec/support/active_record_data/3_2_multi_legacy.txt", "spec/support/active_record_data/4_0_diana.txt", "spec/support/active_record_data/4_0_multi.txt", "spec/support/active_record_data/4_1_diana.txt", "spec/support/active_record_data/4_1_multi.txt", "spec/support/active_record_data/4_2_diana.txt", "spec/support/active_record_data/4_2_diana_legacy.txt", "spec/support/active_record_data/4_2_multi.txt", "spec/support/active_record_data/4_2_multi_legacy.txt", "spec/support/active_record_data/5_0_diana.txt", "spec/support/active_record_data/5_0_multi.txt", "spec/support/ext_verifier.rb", "spec/support/mongoid_versions.rb", "spec/support/rails_versions.rb"]

  if s.respond_to? :specification_version then
    s.specification_version = 4

    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
      s.add_development_dependency(%q, [">= 0"])
      s.add_development_dependency(%q, [">= 0"])
      s.add_development_dependency(%q, [">= 0.2.1"])
      s.add_development_dependency(%q, [">= 1.6.5"])
      s.add_development_dependency(%q, [">= 3.0.0"])
      s.add_development_dependency(%q, [">= 0"])
      s.add_development_dependency(%q, [">= 0"])
    else
      s.add_dependency(%q, [">= 0"])
      s.add_dependency(%q, [">= 0"])
      s.add_dependency(%q, [">= 0.2.1"])
      s.add_dependency(%q, [">= 1.6.5"])
      s.add_dependency(%q, [">= 3.0.0"])
      s.add_dependency(%q, [">= 0"])
      s.add_dependency(%q, [">= 0"])
    end
  else
    s.add_dependency(%q, [">= 0"])
    s.add_dependency(%q, [">= 0"])
    s.add_dependency(%q, [">= 0.2.1"])
    s.add_dependency(%q, [">= 1.6.5"])
    s.add_dependency(%q, [">= 3.0.0"])
    s.add_dependency(%q, [">= 0"])
    s.add_dependency(%q, [">= 0"])
  end
end
awesome_print-1.8.0/.gitignore0000644000004100000410000000045113170662323016417 0ustar  www-datawww-data## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp

## RUBYMINE
.idea

## PROJECT::GENERAL
coverage
rdoc
pkg
.ruby-version
gemfiles/*.gemfile.lock
Gemfile.lock
/tmp
/.bundle
/gemfiles/.bundle

## PROJECT::RVM
.rvmrc

# PROJECT::RBENV
.ruby-gemset
.awesome-print/
awesome_print-1.8.0/CONTRIBUTING.md0000644000004100000410000000564613170662323016673 0ustar  www-datawww-data# Contributing

We love pull requests. Here's a quick guide:

1. Fork the repo.

1. Create your feature branch (`git checkout -b my-new-feature`)

1. Update [CHANGELOG.md](https://github.com/awesome-print/awesome_print/blob/master/CHANGELOG.md) with a brief description of your changes under the `unreleased` heading.

1. Add/Update tests were appropriate

1. Commit your changes (`git commit -am 'Added some feature'`)

1. Push to the branch (`git push origin my-new-feature`)

1. Create new Pull Request

At this point you're waiting on us. We are not super fast at responding, but we will do our best to get to your PR as soon as time permits. We may suggest some changes, improvements or alternatives.

Some things that will increase the chance that your pull request is accepted is to follow the practices described on [Ruby style guide](https://github.com/bbatsov/ruby-style-guide), [Rails style guide](https://github.com/bbatsov/rails-style-guide) and [Better Specs](http://betterspecs.org/).

## Specs

To run all the specs in all gemfiles just run:

```
$ rake
```

To run specs of a single gemfile run:

```
$ appraisal rails-3.2 rake
```

If you want to run a specific spec in a gemfile run:

```
$ appraisal rails-3.2 rspec spec/colors_spec.rb
```

## Contributor Rolecall

Special thanks goes to awesome team of contributors, namely:

* 6fusion.com -- https://github.com/6fusion
* Adam Doppelt -- https://github.com/gurgeous
* Andrew O'Brien -- https://github.com/AndrewO
* Andrew Horsman -- https://github.com/basicxman
* Barry Allard -- https://github.com/steakknife
* Benoit Daloze -- http://github.com/eregon
* Brandon Zylstra -- https://github.com/brandondrew
* Dan Lynn -- https://github.com/danlynn
* Daniel Johnson -- https://github.com/adhd360
* Daniel Bretoi -- http://github.com/danielb2
* Eloy Duran -- http://github.com/alloy
* Elpizo Choi -- https://github.com/fuJiin
* Evan Senter -- https://github.com/evansenter
* George . -- https://github.com/gardelea
* Greg Weber -- https://github.com/gregwebs
* Jan Vansteenkiste -- https://github.com/vStone
* Jeff Felchner -- https://github.com/jfelchner
* Jonathan Davies -- send your Github URL ;-)
* Kevin Olbrich -- https://github.com/olbrich
* Matthew Schulkind -- https://github.com/mschulkind
* Mike McQuaid -- https://github.com/mikemcquaid
* Nami-Doc -- https://github.com/Nami-Doc
* Nicolas Viennot -- https://github.com/nviennot
* Nikolaj Nikolajsen -- https://github.com/nikolajsen
* Richard Hall -- https://github.com/richardardrichard
* Ryan Schlesinger -- https://github.com/ryansch
* Scott Hyndman -- https://github.com/shyndman
* Sean Gallagher -- http://github.com/torandu
* Stephan Hagemann -- https://github.com/shageman
* Tim Harper -- http://github.com/timcharper
* Tobias Crawley -- http://github.com/tobias
* Thibaut Barrère -- https://github.com/thbar
* Trevor Wennblom -- https://github.com/trevor
* vfrride -- https://github.com/vfrride
* Viktar Basharymau -- https://github.com/DNNX
awesome_print-1.8.0/LICENSE0000644000004100000410000000215713170662323015441 0ustar  www-datawww-dataCopyright (c) 2010-2013 Michael Dvorkin
http://www.dvorkin.net
%w(mike dvorkin.net) * "@" || "twitter.com/mid"

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
awesome_print-1.8.0/Appraisals0000644000004100000410000000317013170662323016452 0ustar  www-datawww-dataappraise 'rails-3.2' do
  gem 'rails', '~> 3.2.0'
end

appraise 'rails-4.0' do
  gem 'rails', '~> 4.0.0'
  gem 'json',  '~> 1.8', :platforms => :ruby_19 # Json 2.0 requires Ruby >= 2.0

  # The last version that doesn't need Ruby 2.0 and works with version 4.0 of
  # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
  gem 'mime-types', '2.6.2', :platforms => :ruby_19
end

appraise 'rails-4.1' do
  gem 'rails', '~> 4.1.0'

  # The last version that doesn't need Ruby 2.0 and works with version 4.1 of
  # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
  gem 'mime-types', '2.6.2', :platforms => :ruby_19
end

appraise 'rails-4.2' do
  gem 'rails', '~> 4.2.0'

  # The last version that doesn't need Ruby 2.0 and works with version 4.2 of
  # Rails. This addresses a build problem with Travis for version 1.9.3 of Ruby
  gem 'mime-types', '2.6.2', :platforms => :ruby_19
end

appraise 'rails-5.0' do
  # Only works with Ruby >= 2.2
  gem 'rails', '>= 5.0.0.racecar1', '< 5.1'
end

appraise 'mongoid-3.0' do
  gem 'mongoid', '~> 3.0.0'
end

appraise 'mongoid-3.1' do
  gem 'mongoid', '~> 3.1.0'
  gem 'json',  '~> 1.8', :platforms => :ruby_19 # Json 2.0 requires Ruby >= 2.0
end

appraise 'mongoid-4.0' do
  gem 'mongoid', '~> 4.0.0'
end

appraise 'mongo_mapper' do
  gem 'mongo_mapper'
end

appraise 'ripple' do
  gem 'tzinfo'
  gem 'ripple'
end

appraise 'nobrainer' do
  gem 'nobrainer'

  # When activesupport 5 was released, it required ruby 2.2.2 as a minimum.
  # Locking this down to 4.2.6 allows our Ruby 1.9 tests to keep working.
  gem 'activesupport', '4.2.6', :platforms => :ruby_19
end
awesome_print-1.8.0/CHANGELOG.md0000644000004100000410000001657713170662323016260 0ustar  www-datawww-data## master (unreleased)
  - new things!

## 1.8.0
  - stat("$HOME/.aprc") once [@kstephens] - [#304]
  - ActiveRecord: #joins now show the columns #select'ed [@adrianomitre] - [#211]
  - Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
  - Replaced Fixnum reference with Integer 
  - Colorize ORM class names [@ixti]

## 1.7.0
  - Refactoring by extracting formatters into their own classes [@waldyr] - [#237]
  - Fixes Travis builds and improves tests [@nviennot], [@waldyr], [@gerrywastaken] - [#225], [#228], [#229], [#230], [#231]
  - Creates `awesome_object_data` to encapsulate the logic of printing object internals,
  so Structs and Objects can be printed as one [@waldyr] - [#226]
  - Fixes development dependencies for environments without rake [@aleandros], [@cyberdelia] - [#222], [#216]
  - Documents `ai` method usage [@MaxPleaner] - [#217]
  - Fixes conflict with `mail` and other gems which fake ActiveSupport [@kemmason] - [#200]
  - Improves spec performance and simplicity [@maurogeorge]
  - Handle objects that have a custom #to_hash method [@clonezone]

## 1.6.1
  - Fixes specs on all rails dependencies (Mauro George)
  - Updates specs for mongoid, mongo_mapper and ripple (James Cox)
  - Adds appraisals for simpler version/scenario management (Mauro George)
  - Add Travis (Mauro George)
  - Update documentation (Mauro George)

## 1.6.0
  semi-major release since it's been a while, and there are several
  improvements.
  - Improves support for new mongoid/moped (Velkitor, Francois Bernier et al)
  - Converts specs to rspec 3+ (Adam Jonas, James Cox)
  - Fixes incompatibility with IPAddr (James Cox, Michael Dvorkin)
  - Fixes incompatibility with the money gem (Michael Dvorkin)
  - Fixes AR::Relation presentation (Sergey Ponomarov)
  - Lazy-loads ActionView (Akira Matsuda)
  - Fixes inspection of abstract classes (Jonathan Priddle)
  - Gets most specs passing, and fixes suite (Eoin Kelly)

## 1.2.0
#### NOTE: This is the *last* release supporting Ruby < v1.9.3 and Rails < v3.
  - Added Sequel ORM plugin (Jonathan Davies)
  - Added Ripple plugin (Ruby modeling layer for Riak, Scott Hyndman)
  - Added NoBrainer plugin (Ruby ORM for RethinkDB, Nicolas Viennot)
  - Added formatting for Ruby set objects (Richard Hall)
  - Fixed HTML formatting (Mike McQuaid)
  - Other minor bugs and enhancements

## 1.1.0
  - Objects are no longer recursively formatted by default. Reenable by using :raw => true option.
  - ap(object) now returns nil when running under IRB or Pry
  - Added support for Mongoid 3 and Moped (Nikolaj Nikolajsen)
  - Improved formatting of MongoMapper objects (George .)
  - ActiveRecord::Relation now renders as array (Dan Lynn)
  - Formatting BigDecimal no longer looses precision (Evan Senter)
  - Added AwesomePrint.irb! and AwesomePrint.pry! convenience methods
  - Fixed conflict with the colorize gem
  - Misc tweaks and bug fixes

## 1.0.2
  - Added formatting of Mongoid documents (Adam Doppelt)
  - ActiveRecord objects display attributes only. Use :raw => true to display the entire object
  - ActiveSupport::Date objects get formatted as regular Date
  - Rails.logger.ap colorizes output based on ActiveSupport::LogSubscriber.colorize_logging (default is true)
  - Improved formatting of methods array

## 1.0.1
  - Updated repo tags for Rubygems.org

## 1.0.0 Thanksgiving edition
  - Added ability to format *arbitrary* Ruby object
  - Added :limit option to limit large output for arrays and hashes (Andrew Horsman)
  - Improved HTML formatting when :html => true (Daniel Johnson)
  - Added Mongoid extension (Adam Doppelt)
  - Added Nokogiri extension (Adam Doppelt)
  - Removed Jeweler gem dependency

## 0.4.0
  - 'ap object' now returns the object (Stephan Hagemann)
  - Added :html => true option to enable HTML colors rather that ANSI (ex. Sinatra templates)
  - Added AwesomePrint.force_colors! to allow color output on demand (Andrew O'Brien)
  - Added MongoMapper formatter mixin (Elpizo Choi)
  - Fixed formatting of methods array when object#method is overridden
  - Fixed potential stack errors by checking whether AwesomePrint is already loaded
  - Improved Ruby 1.8.6 and 1.8.7 compatibility
  - Improved Windows compatibility (Viktar Basharymau)

## 0.3.2
  - Make sure Rails mixins get loaded in Rails console when required from .irbrc
  - Fixed an issue with classes that define their own #send method (ex: Socket)
  - Fixed compatibility issue with Liquid gem that defines Module#liquid_methods
  - Fixed hash spec for Ruby < 1.9 where order of hash keys is not guaranteed
  - Added :sorted_hash_keys option to sort hash keys (Ed Ruder)

## 0.3.1 RubyConf X edition
  - Fixed Ruby 1.8.6 compatibility issues (thanks, Tim!)
  - Fixed stack overflow issue with Rails 2.3.x console

## 0.3.0
  - Display object.methods and family in human readable format
  - Objects inherited from Array, Hash, File, Dir, and Struct are shown as their base class
  - Added option to suppress array index in output (Sean Gallagher)
  - Updated README on how to set up ~/.irbrc for MacRuby (Eloy Duran)
  - Specs pass 100% with Ruby 1.8.7/RSpec 1.3 and Ruby 1.9.2/RSpec 2.0

## 0.2.1
  - ap can now be used within Rails templates (ex. <%= ap object %>)
  - Added support for printing Struct

## 0.2.0
  - Added support for logger.ap (including Rails logger)
  - Added support for HashWithIndifferentAccess from ActiveSupport
  - ap now works with scripts that use ActiveRecord/ActiveSupport outside Rails
  - ap now correctly shows file and directory names with fancy characters (shell escape)

## 0.1.4
  - Format BigDecimal and Rational objects as Float scalars
  - Explicit options parameter can override custom defaults
  - Custom defaults are not interfering when running specs
  - Custom defaults now work correctly with Ruby 1.9.x

## 0.1.3
  - Added support for setting custom defaults in ~/.aprc

## 0.1.2
  - Correctly handle empty arrays and hashes
  - Use alias_method instead of alias (fixes non-tty method aliasing)
  - Added awesome_inspect method

## 0.1.1
  - Added support for tableless ActiveRecord models
  - Left align hash keys if @options[:indent] is negative

## 0.1.0
  - Initial Release.

  [#200]: https://github.com/awesome-print/awesome_print/pull/200
  [#212]: https://github.com/awesome-print/awesome_print/pull/212
  [#216]: https://github.com/awesome-print/awesome_print/pull/216
  [#217]: https://github.com/awesome-print/awesome_print/pull/217
  [#222]: https://github.com/awesome-print/awesome_print/pull/222
  [#225]: https://github.com/awesome-print/awesome_print/pull/225
  [#226]: https://github.com/awesome-print/awesome_print/pull/226
  [#228]: https://github.com/awesome-print/awesome_print/pull/228
  [#229]: https://github.com/awesome-print/awesome_print/pull/229
  [#230]: https://github.com/awesome-print/awesome_print/pull/230
  [#231]: https://github.com/awesome-print/awesome_print/pull/231
  [#232]: https://github.com/awesome-print/awesome_print/pull/232
  [#237]: https://github.com/awesome-print/awesome_print/pull/237

  [@aleandros]: https://github.com/aleandros
  [@clonezone]: https://github.com/clonezone
  [@cyberdelia]: https://github.com/cyberdelia
  [@gerrywastaken]: https://github.com/gerrywastaken
  [@ixti]: https://github.com/ixti
  [@jtnegrotto]: https://github.com/jtnegrotto
  [@kemmason]: https://github.com/kemmason
  [@maurogeorge]: https://github.com/maurogeorge
  [@MaxPleaner]: https://github.com/MaxPleaner
  [@nviennot]: https://github.com/nviennot
  [@waldyr]: https://github.com/waldyr
awesome_print-1.8.0/README.md0000644000004100000410000002270613170662323015715 0ustar  www-datawww-data## Awesome Print ##

[![RubyGems][gem_version_badge]][ruby_gems]
[![Travis CI][travis_ci_badge]][travis_ci]
[![Code Climate][code_climate_badge]][code_climate]
[![Code Climate Coverage][code_climate_coverage_badge]][code_climate]
[![RubyGems][gem_downloads_badge]][ruby_gems]
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/awesome-print/awesome_print?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


Awesome Print is a Ruby library that pretty prints Ruby objects in full color
exposing their internal structure with proper indentation. Rails ActiveRecord
objects and usage within Rails templates are supported via included mixins.

__NOTE__: awesome_print v1.2.0 is the last release supporting Ruby versions
prior to v1.9.3 and Rails versions prior to v3.0. The upcoming awesome_print
v2.0 will *require* Ruby v1.9.3 or later and Rails v3.0 or later.

### Installation ###
    # Installing as Ruby gem
    $ gem install awesome_print

    # Cloning the repository
    $ git clone git://github.com/awesome-print/awesome_print.git

### Usage ###

```ruby
require "awesome_print"
ap object, options = {}
```

Default options:

```ruby
indent:        4,      # Number of spaces for indenting.
index:         true,   # Display array indices.
html:          false,  # Use ANSI color codes rather than HTML.
multiline:     true,   # Display in multiple lines.
plain:         false,  # Use colors.
raw:           false,  # Do not recursively format instance variables.
sort_keys:     false,  # Do not sort hash keys.
sort_vars:     true,   # Sort instance variables.
limit:         false,  # Limit arrays & hashes. Accepts bool or int.
ruby19_syntax: false,  # Use Ruby 1.9 hash syntax in output.
color: {
  args:       :pale,
  array:      :white,
  bigdecimal: :blue,
  class:      :yellow,
  date:       :greenish,
  falseclass: :red,
  fixnum:     :blue,
  float:      :blue,
  hash:       :pale,
  keyword:    :cyan,
  method:     :purpleish,
  nilclass:   :red,
  rational:   :blue,
  string:     :yellowish,
  struct:     :pale,
  symbol:     :cyanish,
  time:       :greenish,
  trueclass:  :green,
  variable:   :cyanish
}
```

Supported color names:

```ruby
:gray, :red, :green, :yellow, :blue, :purple, :cyan, :white
:black, :redish, :greenish, :yellowish, :blueish, :purpleish, :cyanish, :pale
```

Use `Object#ai` to return an ASCII encoded string:

```ruby
irb> "awesome print".ai
=> "\e[0;33m\"awesome print\"\e[0m"
```

### Examples ###

```ruby
$ cat > 1.rb
require "awesome_print"
data = [ false, 42, %w(forty two), { :now => Time.now, :class => Time.now.class, :distance => 42e42 } ]
ap data
^D
$ ruby 1.rb
[
    [0] false,
    [1] 42,
    [2] [
        [0] "forty",
        [1] "two"
    ],
    [3] {
           :class => Time < Object,
             :now => Fri Apr 02 19:55:53 -0700 2010,
        :distance => 4.2e+43
    }
]

$ cat > 2.rb
require "awesome_print"
data = { :now => Time.now, :class => Time.now.class, :distance => 42e42 }
ap data, :indent => -2  # <-- Left align hash keys.
^D
$ ruby 2.rb
{
  :class    => Time < Object,
  :now      => Fri Apr 02 19:55:53 -0700 2010,
  :distance => 4.2e+43
}

$ cat > 3.rb
require "awesome_print"
data = [ false, 42, %w(forty two) ]
data << data  # <-- Nested array.
ap data, :multiline => false
^D
$ ruby 3.rb
[ false, 42, [ "forty", "two" ], [...] ]

$ cat > 4.rb
require "awesome_print"
class Hello
  def self.world(x, y, z = nil, &blk)
  end
end
ap Hello.methods - Class.methods
^D
$ ruby 4.rb
[
    [0] world(x, y, *z, &blk) Hello
]

$ cat > 5.rb
require "awesome_print"
ap (''.methods - Object.methods).grep(/!/)
^D
$ ruby 5.rb
[
    [ 0] capitalize!()           String
    [ 1]      chomp!(*arg1)      String
    [ 2]       chop!()           String
    [ 3]     delete!(*arg1)      String
    [ 4]   downcase!()           String
    [ 5]     encode!(*arg1)      String
    [ 6]       gsub!(*arg1)      String
    [ 7]     lstrip!()           String
    [ 8]       next!()           String
    [ 9]    reverse!()           String
    [10]     rstrip!()           String
    [11]      slice!(*arg1)      String
    [12]    squeeze!(*arg1)      String
    [13]      strip!()           String
    [14]        sub!(*arg1)      String
    [15]       succ!()           String
    [16]   swapcase!()           String
    [17]         tr!(arg1, arg2) String
    [18]       tr_s!(arg1, arg2) String
    [19]     upcase!()           String
]

$ cat > 6.rb
require "awesome_print"
ap 42 == ap(42)
^D
$ ruby 6.rb
42
true
$ cat 7.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => true
^D
$ ruby 7.rb
[
    [  0] 1,
    [  1] 2,
    [  2] 3,
    [  3] .. [996],
    [997] 998,
    [998] 999,
    [999] 1000
]

$ cat 8.rb
require "awesome_print"
some_array = (1..1000).to_a
ap some_array, :limit => 5
^D
$ ruby 8.rb
[
    [  0] 1,
    [  1] 2,
    [  2] .. [997],
    [998] 999,
    [999] 1000
]
```

### Example (Rails console) ###
```ruby
$ rails console
rails> require "awesome_print"
rails> ap Account.limit(2).all
[
    [0] # {
                     :id => 1,
                :user_id => 5,
            :assigned_to => 7,
                   :name => "Hayes-DuBuque",
                 :access => "Public",
                :website => "http://www.hayesdubuque.com",
        :toll_free_phone => "1-800-932-6571",
                  :phone => "(111)549-5002",
                    :fax => "(349)415-2266",
             :deleted_at => nil,
             :created_at => Sat, 06 Mar 2010 09:46:10 UTC +00:00,
             :updated_at => Sat, 06 Mar 2010 16:33:10 UTC +00:00,
                  :email => "info@hayesdubuque.com",
        :background_info => nil
    },
    [1] # {
                     :id => 2,
                :user_id => 4,
            :assigned_to => 4,
                   :name => "Ziemann-Streich",
                 :access => "Public",
                :website => "http://www.ziemannstreich.com",
        :toll_free_phone => "1-800-871-0619",
                  :phone => "(042)056-1534",
                    :fax => "(106)017-8792",
             :deleted_at => nil,
             :created_at => Tue, 09 Feb 2010 13:32:10 UTC +00:00,
             :updated_at => Tue, 09 Feb 2010 20:05:01 UTC +00:00,
                  :email => "info@ziemannstreich.com",
        :background_info => nil
    }
]
rails> ap Account
class Account < ActiveRecord::Base {
                 :id => :integer,
            :user_id => :integer,
        :assigned_to => :integer,
               :name => :string,
             :access => :string,
            :website => :string,
    :toll_free_phone => :string,
              :phone => :string,
                :fax => :string,
         :deleted_at => :datetime,
         :created_at => :datetime,
         :updated_at => :datetime,
              :email => :string,
    :background_info => :string
}
rails>
```

### IRB integration ###
To use awesome_print as default formatter in irb and Rails console add the following
code to your ~/.irbrc file:

```ruby
require "awesome_print"
AwesomePrint.irb!
```

### PRY integration ###
If you miss awesome_print's way of formatting output, here's how you can use it in place
of the formatting which comes with pry. Add the following code to your ~/.pryrc:

```ruby
require "awesome_print"
AwesomePrint.pry!
```

### Logger Convenience Method ###
awesome_print adds the 'ap' method to the Logger and ActiveSupport::BufferedLogger classes
letting you call:

    logger.ap object

By default, this logs at the :debug level. You can override that globally with:

    :log_level => :info

in the custom defaults (see below). You can also override on a per call basis with:

    logger.ap object, :warn

### ActionView Convenience Method ###
awesome_print adds the 'ap' method to the ActionView::Base class making it available
within Rails templates. For example:

    <%= ap @accounts.first %>   # ERB
    != ap @accounts.first       # HAML

With other web frameworks (ex: in Sinatra templates) you can explicitly request HTML
formatting:

    <%= ap @accounts.first, :html => true %>
    
### String Convenience Methods ###
Use methods such as `.red` to set string color:

```ruby
irb> puts "red text".red
red text # (it's red)
```

### Setting Custom Defaults ###
You can set your own default options by creating ``.aprc`` file in your home
directory. Within that file assign your  defaults to ``AwesomePrint.defaults``.
For example:

```ruby
# ~/.aprc file.
AwesomePrint.defaults = {
  :indent => -2,
  :color => {
    :hash  => :pale,
    :class => :white
  }
}
```

## Versioning

AwesomePrint follows the [Semantic Versioning](http://semver.org/) standard.

### Contributing ###
See [CONTRIBUTING.md](CONTRIBUTING.md) for information.

### License ###
Copyright (c) 2010-2016 Michael Dvorkin and contributors

http://www.dvorkin.net

%w(mike dvorkin.net) * "@" || "twitter.com/mid"

Released under the MIT license. See LICENSE file for details.

[gem_version_badge]: https://img.shields.io/gem/v/awesome_print.svg?style=flat
[gem_downloads_badge]: http://img.shields.io/gem/dt/awesome_print.svg?style=flat
[ruby_gems]: http://rubygems.org/gems/awesome_print
[travis_ci]: http://travis-ci.org/awesome-print/awesome_print
[travis_ci_badge]: https://img.shields.io/travis/awesome-print/awesome_print/master.svg?style=flat
[code_climate]: https://codeclimate.com/github/awesome-print/awesome_print
[code_climate_badge]: http://img.shields.io/codeclimate/github/awesome-print/awesome_print.svg?style=flat
[code_climate_coverage_badge]: https://codeclimate.com/github/awesome-print/awesome_print/badges/coverage.svg