awesome-print / awesome_print Goto Github PK
View Code? Open in Web Editor NEWPretty print your Ruby objects with style -- in full color and with proper indentation
Home Page: http://github.com/michaeldv/awesome_print
License: MIT License
Pretty print your Ruby objects with style -- in full color and with proper indentation
Home Page: http://github.com/michaeldv/awesome_print
License: MIT License
Hi!
I noticed that a HashWithIndifferentAccess (< Hash) in MongoMapper doesn't seem to get colorized, whereas just calling .to_hash on it works.
I suspect this is because AP checks for strict class equality, rather than inheritance ? (wild guess :-))
Thanks for your work on AP, it's great!
I was wondering if anyone else had any problems with colors using ap.
All I have in my .irbrc is require for rubygems and ap. ( I thought some of my other custom methods might be interfering - so I removed everything).
ap works - when I print and array or hash - it's nicely formatted like it's supposed to be. However there are no colors.
I'm running on ruby 1.9.2p180 (from rubyintaller website) on Windows XP sp3.
I tried both cmd and powershell to no avail.
Am I missing something?
I was in irb getting .methods on a Mechanize document (d = agent.get(..)). Is this an ap issue?
ruby-1.9.2-p136 :039 > d.methods
/Users/danhealy/.rvm/gems/ruby-1.9.2-p136@global/gems/awesome_print-0.3.2/lib/ap/core_ext/array.rb:19: [BUG] Segmentation fault
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
-- control frame ----------
c:0027 p:---- s:0100 b:0100 l:000099 d:000099 CFUNC :&
c:0026 p:0032 s:0096 b:0096 l:002248 d:000095 LAMBDA /Users/danhealy/.rvm/gems/ruby-1.9.2-p136@global/gems/awesome_print-0.3.2/lib/ap/core_ext/array.rb:19
c:0025 p:---- s:0092 b:0092 l:000091 d:000091 FINISH
c:0024 p:0092 s:0090 b:0090 l:000089 d:000089 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-token.rb:98
c:0023 p:1122 s:0084 b:0084 l:000083 d:000083 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:869
c:0022 p:0092 s:0075 b:0075 l:001b78 d:000074 BLOCK /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:731
c:0021 p:---- s:0070 b:0070 l:000069 d:000069 FINISH
c:0020 p:---- s:0068 b:0068 l:000067 d:000067 CFUNC :call
c:0019 p:0349 s:0063 b:0063 l:000062 d:000062 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/slex.rb:236
c:0018 p:0056 s:0055 b:0055 l:000054 d:000054 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/slex.rb:75
c:0017 p:0048 s:0050 b:0050 l:000049 d:000049 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:286
c:0016 p:0017 s:0046 b:0046 l:000045 d:000045 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:262
c:0015 p:0028 s:0041 b:0041 l:000024 d:000040 BLOCK /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:233
c:0014 p:---- s:0038 b:0038 l:000037 d:000037 FINISH
c:0013 p:---- s:0036 b:0036 l:000035 d:000035 CFUNC :loop
c:0012 p:0009 s:0033 b:0033 l:000024 d:000032 BLOCK /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:229
c:0011 p:---- s:0031 b:0031 l:000030 d:000030 FINISH
c:0010 p:---- s:0029 b:0029 l:000028 d:000028 CFUNC :catch
c:0009 p:0023 s:0025 b:0025 l:000024 d:000024 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:228
c:0008 p:0046 s:0022 b:0022 l:000fc8 d:000fc8 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:155
c:0007 p:0011 s:0019 b:0019 l:0013f8 d:000018 BLOCK /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:70
c:0006 p:---- s:0017 b:0017 l:000016 d:000016 FINISH
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :catch
c:0004 p:0183 s:0011 b:0011 l:0013f8 d:0013f8 METHOD /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:69
c:0003 p:0142 s:0006 b:0006 l:0014e8 d:002518 EVAL /Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0014e8 d:0014e8 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/bin/irb:16:in `<main>'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:69:in `start'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:69:in `catch'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:70:in `block in start'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top_level_statement'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/slex.rb:236:in `match_io'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/slex.rb:236:in `call'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:731:in `block in lex_int2'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-lex.rb:869:in `identify_identifier'
/Users/danhealy/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/irb/ruby-token.rb:98:in `Token'
/Users/danhealy/.rvm/gems/ruby-1.9.2-p136@global/gems/awesome_print-0.3.2/lib/ap/core_ext/array.rb:19:in `block (2 levels) in <class:Array>'
/Users/danhealy/.rvm/gems/ruby-1.9.2-p136@global/gems/awesome_print-0.3.2/lib/ap/core_ext/array.rb:19:in `&'
-- C level backtrace information -------------------------------------------
[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
Given a hash using Symbols for keys, it would be nice to have a formatting option that used the Ruby 1.9 style key: value
formatting instead of :key => value
.
pp
does this without colours:
[#<Twostroke::AST::MultiExpression:0x0000010083dff0
@left=
#<Twostroke::AST::Assignment:0x0000010083e6f8
@left=#<Twostroke::AST::Variable:0x00000100846808 @name="a">,
@right=#<Twostroke::AST::Number:0x000001008435b8 @number=1.0>>,
@right=#<Twostroke::AST::Number:0x000001008418f8 @number=2.0>>]
pry
does this with limited colours, but is slow to require.
AwesomePrint looks to be the best alternative to both of these, but it really needs to support regular old objects with attributes.
Hi Mike! It's too awesome.
.rvm/gems/ruby-1.9.2-p136/gems/awesome_print-0.3.1/lib/ap/mixin/active_support.rb:18:in `printable_with_active_support': uninitialized constant ActiveSupport::TimeWithZone (NameError)
Hasn't worked with Rails 3.0.1 or 3.0.3
$> ./script/rails server -u
/opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/object.rb:10: undefined method `liquid_methods' for class `Object' (NameError)
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/array.rb:59:in `grep'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/object.rb:17:in `original_grep'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/array.rb:59:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/array.rb:59:in `original_grep'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/array.rb:59:in `grep'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/object.rb:7
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:239:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap.rb:7
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap.rb:6:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/awesome_print-0.3.1/lib/ap.rb:6
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:64:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:64:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:62:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:62:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:51:in `each'
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler/runtime.rb:51:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/bundler-1.0.3/lib/bundler.rb:112:in `require'
from /Users/jesse/projects/projectdx-pdxrails/config/application.rb:7
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:28
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from /opt/local/lib/ruby/gems/1.8/gems/railties-3.0.3/lib/rails/commands.rb:27
from ./script/rails:6:in `require'
from ./script/rails:6
Any way to make it treat ActiveRecord::Relation (i.e. Model.where) results similar to Array results (i.e. Model.find)?
The way I get around is is simply this, but a bit a of a pain:
Genre.where(:id => [1,2]).each {|g| ap g }
IRB:
ap Genre.where(:id => [1,2])
[#<Genre id: 1, name: "Blues", created_at: "2011-03-03 05:21:08", updated_at: "2011-03-05 18:05:19", id3_id: 0>, #<Genre id: 2, name: "Classic Rock", created_at: "2011-03-03 05:21:08", updated_at: "2011-03-03 05:21:08", id3_id: 1>]
whereas using find works fine:
ap Genre.find [1,2]
[
[0] #Genre:0x000000018c2408 {
:id => 1,
:name => "Blues",
:created_at => Thu, 03 Mar 2011 05:21:08 UTC +00:00,
:updated_at => Sat, 05 Mar 2011 18:05:19 UTC +00:00,
:id3_id => 0
},
[1] #Genre:0x000000018c22a0 {
:id => 2,
:name => "Classic Rock",
:created_at => Thu, 03 Mar 2011 05:21:08 UTC +00:00,
:updated_at => Thu, 03 Mar 2011 05:21:08 UTC +00:00,
:id3_id => 1
}
]
Is it supports active model?
Perhaps an additional option could be added so that long arrays, hashes, etc could not fill the screen? e.g. ap would print the first 3 lines, a '...', then the last 3? (if it were configured to output 3 lines)
I installed ap:
"Successfully installed awesome_print-0.2.1"
Now, when I go to the console and try to require 'ap', get the following error:
LoadError: cannot load such file -- ap
from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in require' from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in
block in require'
from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in block in load_dependency' from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:554:in
new_constants_in'
from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:198:in load_dependency' from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/activesupport-3.0.0.beta4/lib/active_support/dependencies.rb:212:in
require'
from (irb):1
from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.0.beta4/lib/rails/commands/console.rb:47:in start' from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.0.beta4/lib/rails/commands/console.rb:8:in
start'
from /Users/cbmeeks/.rvm/gems/ruby-1.9.2-head/gems/railties-3.0.0.beta4/lib/rails/commands.rb:23:in <top (required)>' from script/rails:9:in
require'
from script/rails:9:in `
I am using rvm, ruby 1.9.2-head, Snow Leopard
Other gems load fine like pp.
Any help would be appreciated.
Thanks!
Disclaimer: I haven't debugged the entire stack to figure out the problem here. However, the problem goes away if awesome_print isn't in my Gemfile.
Example code:
def foo &block puts block.to_source end foo { puts 'hi' }
crashes with:
NoMethodError: undefined method `<=>' for :defined:Symbol from /var/lib/gems/1.8/gems/awesome_print-0.3.2/lib/ap/core_ext/array.rb:22:in `sort!' from /var/lib/gems/1.8/gems/awesome_print-0.3.2/lib/ap/core_ext/array.rb:22:in `-' from /var/lib/gems/1.8/gems/sexp_processor-3.0.5/lib/sexp_processor.rb:167:in `process' from /var/lib/gems/1.8/gems/sourcify-0.4.2/lib/sourcify/proc/parser/converter.rb:22:in `to_code' from /var/lib/gems/1.8/gems/sourcify-0.4.2/lib/sourcify/proc/parser.rb:20:in `source' from /var/lib/gems/1.8/gems/sourcify-0.4.2/lib/sourcify/proc/methods/to_source.rb:38:in `to_source'
I have this in my .aprc:
AwesomePrint.defaults = {
:indent => 2
}
The custom indent breaks methods_spec, unfortunately. I was able to workaround the problem by temporarily modifying my .aprc, of course.
How to reproduce:
>> a = {}
=> {}
>> ap a
NoMethodError: undefined method `+' for nil:NilClass
from /opt/ree/lib/ruby/gems/1.8/gems/awesome_print-0.1.1/lib/ap/awesome_print.rb:71:in `awesome_hash'
from /opt/ree/lib/ruby/gems/1.8/gems/awesome_print-0.1.1/lib/ap/awesome_print.rb:128:in `send'
from /opt/ree/lib/ruby/gems/1.8/gems/awesome_print-0.1.1/lib/ap/awesome_print.rb:128:in `awesome'
from /opt/ree/lib/ruby/gems/1.8/gems/awesome_print-0.1.1/lib/ap/awesome_print.rb:37:in `puts'
from /opt/ree/lib/ruby/gems/1.8/gems/awesome_print-0.1.1/lib/ap/core_ext/kernel.rb:10:in `ap'
from (irb):7
We are experiencing a strange issue in our development environment when using AP in the rails console.
When my ~/.irbrc file contains the following snippet, as recommended in the AP docs, we are unable to upload images in our dev env using Paperclip:
# FIXME : Removed since it was conflicting with PaperClip!?
#
# AWESOME PRINT
#require "ap"
#unless IRB.version.include?('DietRB')
# IRB::Irb.class_eval do
# def output_value
# ap @context.last_value
# end
# end
#else # MacRuby
# IRB.formatter = Class.new(IRB::Formatter) do
# def inspect_object(object)
# object.ai
# end
# end.new
#end
Removing this snippet resolves the issue completely. Otherwise the rails console will hang w/ 100% CPU usage until a control-c is given to break out of it. I turned to awesome_print changes to fix our problem due to the backtrace I saw in the console after control-c. The backtrace.
>> arp = ArtistPhoto.create(:image => File.open(Rails.root.to_s + '/public/images/twitter.png', 'rb'), :artist_id => 1)
^CIRB::Abort: abort then interrupt!!
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/aws/models/storage/file.rb:75:in `call'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/aws/models/storage/file.rb:75:in `owner='
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/attributes.rb:144:in `block in merge_attributes'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/attributes.rb:141:in `each'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/attributes.rb:141:in `merge_attributes'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/model.rb:10:in `initialize'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:105:in `new'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:105:in `new'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/aws/models/storage/files.rb:105:in `new'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:92:in `block in load'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:91:in `each'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:91:in `load'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/aws/models/storage/directories.rb:33:in `get'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/aws/models/storage/files.rb:32:in `all'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:131:in `lazy_load'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/fog-1.0.0/lib/fog/core/collection.rb:18:in `=='
... 27 levels...
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:26:in `format'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/inspector.rb:104:in `unnested'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/inspector.rb:71:in `awesome'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:144:in `block (2 levels) in awesome_object'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:297:in `indented'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:143:in `block in awesome_object'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:131:in `map'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:131:in `awesome_object'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:56:in `awesome_self'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/formatter.rb:28:in `format'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/inspector.rb:104:in `unnested'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/inspector.rb:71:in `awesome'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/core_ext/kernel.rb:10:in `ai'
from /Users/glenn/.rvm/gems/ruby-1.9.2-p290@thrillcall/gems/awesome_print-1.0.1/lib/awesome_print/core_ext/kernel.rb:15:in `ap'
from /Users/glenn/.irbrc:51:in `output_value'
from /Users/glenn/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'>> quit
Commenting out the console integration completely resolves the issue. Any thoughts?
Rails 2.3.14 with the following related gems:
gem "paperclip", "2.4.5"
gem "delayed_paperclip", "2.4.5.1"
gem "paperclip-meta", "0.2"
gem "awesome_print", "1.0.1"
gem "fog", "1.0.0"
/Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/awesome_print-0.4.0/lib/ap/mixin/action_view.rb:17:in `<top (required)>': uninitialized constant ActionView::Base (NameError)
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/awesome_print-0.4.0/lib/awesome_print.rb:19:in `<top (required)>'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler/runtime.rb:68:in `require'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler/runtime.rb:66:in `each'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler/runtime.rb:66:in `block in require'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler/runtime.rb:55:in `each'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler/runtime.rb:55:in `require'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/bundler-1.1.rc/lib/bundler.rb:128:in `require'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/config/environment.rb:16:in `<top (required)>'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/app.rb:1:in `require'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/app.rb:1:in `<top (required)>'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/spec/spec_helper.rb:13:in `require'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/spec/spec_helper.rb:13:in `<top (required)>'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/spec/api_spec.rb:1:in `require'
from /Users/grimen/Dropbox/Development/projects/merchii/merchii-api/spec/api_spec.rb:1:in `<top (required)>'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
from /Users/grimen/.rvm/gems/ruby-1.9.3-p0/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [/Users/grimen/.rvm/rubies/ruby-1.9.3-p0/bi...]
I just installed the latest awsome_print as a plugin in my Rails 3.0.3 project and am now getting
DEPRECATION WARNING: Use toplevel init.rb; rails/init.rb is deprecated: /home/mike/sim5/vendor/plugins/awesome_print/rails/init.rb
Also (separate issue), "gem install awesome_print" is not finding the gem anywhere. Is it in a particular repository somewhere?
irb(main):001:0> ap Investor.ancestors
NoMethodError: undefined method `abstract_class?' for Object:Class
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.0.10/lib/active_record/base.rb:1212:in `class_of_active_record_descendant'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.0.10/lib/active_record/base.rb:830:in `base_class'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.0.10/lib/active_record/base.rb:962:in `compute_table_name'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.0.10/lib/active_record/base.rb:607:in `reset_table_name'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.0.10/lib/active_record/base.rb:597:in `table_name'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.0.10/lib/active_record/base.rb:685:in `columns'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/mixin/active_record.rb:46:in `awesome_active_record_class'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:171:in `awesome'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:69:in `block (2 levels) in awesome_array'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:297:in `indented'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:68:in `block in awesome_array'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:62:in `each'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:62:in `inject'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:62:in `awesome_array'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/awesome_print.rb:171:in `awesome'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/core_ext/kernel.rb:10:in `ai'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/awesome_print-0.4.0/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):1
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/commands/console.rb:44:in `start'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/commands/console.rb:8:in `start'
from /home/raykin/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):002:0>
If I have a to_json, can I have AP do this:
ap job.to_json
and it will pretty print the JSON for me.
{
“job_id” : "JD12345",
“title” : “Network Engineer”,
}
Just a thought.
There is a gem that is actually called ap, that when installed with gem install ap, conflicts with the require for awesome_print. It is the Associated Press ap gem. It would be preferable to have the require match the gem name to avoid conflicts.
$ gem install awesome_print -v 0.4.0 ERROR: While executing gem ... (ArgumentError) marshal data too short
Version 0.3.2 installs without any problems
Hi Michael,
Like your awesome_print. It's truly awesome! We want to use it in our Rails app, but since we are not using ActiveRecord (it's not even loaded), when we run ap, it complains about missing constant ActiveRecord::Base. Here is the stack trace for this problem:
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant'
from C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
from C:/Ruby/lib/ruby/gems/1.8/gems/awesome_print-0.1.2/lib/ap/mixin/rails.rb:17:in `printable'
from C:/Ruby/lib/ruby/gems/1.8/gems/awesome_print-0.1.2/lib/ap/awesome_print.rb:128:in `awesome'
from C:/Ruby/lib/ruby/gems/1.8/gems/awesome_print-0.1.2/lib/ap/core_ext/kernel.rb:10:in `send'
from C:/Ruby/lib/ruby/gems/1.8/gems/awesome_print-0.1.2/lib/ap/core_ext/kernel.rb:10:in `ai'
from C:/Ruby/lib/ruby/gems/1.8/gems/awesome_print-0.1.2/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):12
We are running Rails 2.3.5 on Ruby 1.8.6 on Windows platform.
Do you think it's a bug and can be easily fixed?
Thanks,
Alex
Hi Mike! It's too awesome.
For rails 2 apps.
Currently, it just prints the inspection of the object. Would be nice to see the pretty print of the object instead.
A common Rails development pattern to output debug info is changing
def update
@user = User.find(1)
end
into
def update
@user = User.find(1)
raise @user.inspect
end
Is there something you can return to raise so that the exception screen will display the awesome-printed object? An obvious way would be to add Object#ap_inspect, but I could see how you might not want to monkeypatch that.
>> ap 3 NameError: uninitialized constant ActiveSupport::TimeWithZone from /home/wilkboar/beta_myfavoritepal/vendor/rails/activesupport/lib/active_support/dependencies.rb:263:in `load_missing_constant' from /home/wilkboar/beta_myfavoritepal/vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in `const_missing' from /home/wilkboar/.gems/gems/awesome_print-0.2.1/lib/ap/mixin/active_support.rb:18:in `printable' from /home/wilkboar/.gems/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:149:in `awesome' from /home/wilkboar/.gems/gems/awesome_print-0.2.1/lib/ap/core_ext/kernel.rb:10:in `send' from /home/wilkboar/.gems/gems/awesome_print-0.2.1/lib/ap/core_ext/kernel.rb:10:in `ai' from /home/wilkboar/.gems/gems/awesome_print-0.2.1/lib/ap/core_ext/kernel.rb:15:in `ap' from (irb):7 from :0
with rails 2.0.2
timcharper@timcharper:~/projects $ gem install awesome_print
Successfully installed awesome_print-0.3.0
1 gem installed
timcharper@timcharper:~/projects $ irb
Bond activated
irb(main):001:0> require 'ap'
=> true
irb(main):002:0> ap String.methods
LocalJumpError: no block given
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:264:in `times'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:264:in `method_tuple'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:178:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `map'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:176:in `methods_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:54:in `awesome_array'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/awesome_print.rb:165:in `awesome'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `send'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:10:in `ai'
from /Library/Ruby/Gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):9
Thanks for all your hard work on the recent release! I'm trying out 1.0.1.
All is well except for one minor issue... I love awesome_print so much that I generally load it first. My .irbrc loads it early. My rails app.rb loads it early. My standalone script helper loads it nearly on the first line.
Unfortunately, this prevents ext/nokogiri from loading. This works:
require "nokogiri"
require "awesome_print"
and this doesn't:
require "awesome_print"
require "nokogiri"
I'm worried that a lot of folks will never even discover the nokogiri extension. I don't have an obvious fix offhand, unfortunately.
Hi,
During debugging of problems, I find myself changing from code like this
def method
something
end
to
def method
res = something
ap res
res
end
I think it would be awesome if I could just write the following to achieve the same thing:
def method
ap something
end
This is what this commit does:
shageman@05726bf
Does this make sense to anyone?
Do you think it is unintuitve or dangerous?
Or do you think it's awesome?
In our project we included awesome_print into our Gemfile and started getting random seg faults on the following ruby versions and rails version. It would consistently make our CI server fail with a seg fault, again, somewhere randomly, never consistant.
Interestingly enough on my mac I had no problems.
This took a while to resolve, but sure enough awesome_print was included and it started failing, once removed completely we have had a successful build again.
ruby 1.9.2p188 (2011-02-18 revision 30909) [x86_64-linux]
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
ruby 1.9.2p188 (2011-03-28 revision 31204) [x86_64-linux]
rails 3.0.7
Tested 0.3.0 and 0.3.1 in 2.3.5 and 2.3.8 and both now default to standard #inspect behavior (albeit with color). I tested 0.3.0 with the stack overflow fix from 0.3.1, since I couldn't even get it to run with Rails without the fix.
I've recently added awesome_print to my Gemfile tracking the development branch. When ap is part of my bundle, running rake tasks goes crazy. Setting :require => false to try and add the dependency without including it globally also doesn't seem to help. Any ideas?
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:30: warning: already initialized constant RAKEVERSION
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:402: warning: already initialized constant EMPTY_TASK_ARGS
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:450: warning: already initialized constant EMPTY
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:962: warning: already initialized constant RUBY
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1031: warning: already initialized constant LN_SUPPORTED
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1240: warning: already initialized constant ARRAY_METHODS
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1243: warning: already initialized constant MUST_DEFINE
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1247: warning: already initialized constant MUST_NOT_DEFINE
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1251: warning: already initialized constant SPECIAL_RETURN
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1257: warning: already initialized constant DELEGATING_METHODS
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1561: warning: already initialized constant DEFAULT_IGNORE_PATTERNS
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1567: warning: already initialized constant DEFAULT_IGNORE_PROCS
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1604: warning: already initialized constant FileList
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1630: warning: already initialized constant EARLY
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:1960: warning: already initialized constant DEFAULT_RAKEFILES
rake aborted!
stack level too deep
rake aborted!
wrong number of arguments (1 for 0)
/Users/blake/.rvm/rubies/ruby-1.9.2-p290-railsexpress/lib/ruby/1.9.1/rake.rb:2447:in `rakefile_location': wrong number of arguments (1 for 0) (ArgumentError)
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/gems/rake-0.9.2.2/lib/rake/application.rb:154:in `display_error_message'
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/gems/rake-0.9.2.2/lib/rake/application.rb:142:in `rescue in standard_exception_handling'
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/gems/rake-0.9.2.2/lib/rake/application.rb:132:in `standard_exception_handling'
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/bin/rake:19:in `load'
from /Users/blake/.rvm/gems/ruby-1.9.2-p290-railsexpress@gateguru/bin/rake:19:in `<main>'
I’m the author of DietRB, a rewrite of IRB that’s currently being shipped with MacRuby http://github.com/MacRuby/DietRB. After we released MacRuby 0.7, a few questions regarding your gem came in. The problem is that I do not support monkey patching the internals in order to change formatting of the output.
I wrote an email on the mailing-list on how to solve this and was wondering if you'd like to incorporate it in your README? http://lists.macosforge.org/pipermail/macruby-devel/2010-October/006146.html
Thanks,
Eloy
Not sure how hard it is, but I notice that ActiveLdap objects are not printed awesomely.
Is the output of logger.ap supposed to be colorized? I can call the method from my controller (in rails), but doesn't colorize the output (it yields the same result as logger.info object.inspect). I do have AP colorization working in the console. The gem is definitely loading and the method works - just doesn't colorize. I haven't changed any defaults.
(Along the same lines, is the output from the ap helper supposed to be colorized as well? It isn't for me.)
gem 'awesome_print'
gem 'colorize'
this creates a conflict
ruby-1.9.2-p180-mri :002 > ap Article.last
ArgumentError: wrong number of arguments (1 for 0)
Solution (254):
def colorize(str, type)
str = CGI.escapeHTML(str) if @options[:html]
if @options[:plain] || !@options[:color][type] || !colorize?
@options[:html] ? "<pre>#{s}</pre>" : str
elsif !@options[:html] && @options[:color] && type
str.send(@options[:color][type])
else
str.send(@options[:color][type], @options[:html])
end
end
Ruby 1.8.7p302
awesome_print 0.3.0
only happens in rails console (2.3.10). irb works fine
script/console
Loading development environment (Rails 2.3.10)
/usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `-':SystemStackError: stack level too deep
/usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `-':SystemStackError: stack level too deep
/usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `-':SystemStackError: stack level too deep
>> x = User.find(2)
/usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `&': stack level too deep (SystemStackError)
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `original_388'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `send'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `&'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `original_388'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `send'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `&'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `original_388'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:19:in `send'
... 9267 levels...
from /usr/lib/ruby/1.8/irb.rb:71:in `start'
from /usr/lib/ruby/1.8/irb.rb:70:in `catch'
from /usr/lib/ruby/1.8/irb.rb:70:in `start'
from /usr/bin/irb:13
OpenStruct objects typically translates directly from hashes and ap'ing a hash is already built in.
The following code fails with backtrace that follows:
require 'ap'
require 'net/telnet'
link = Net::Telnet::new("Host" => 'www.google.com', "Port" => 80, 'Telnetmode' => false, 'Prompt' => /.*/, 'Waittime' => 10.0, 'Binmode' => true)
link.cmd("GET / HTTP/1.1\r\n"){|c| puts c}
Back Trace:
/usr/share/hive/ruby/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/object.rb:12:in send': wrong number of arguments (1 for 2) (ArgumentError) from /usr/share/hive/ruby/1.8/gems/awesome_print-0.3.1/lib/ap/core_ext/object.rb:12:in
methods'
from /usr/lib/ruby/1.8/delegate.rb:134:in initialize' from /usr/lib/ruby/1.8/delegate.rb:200:in
initialize'
from /usr/lib/ruby/1.8/net/telnet.rb:371:in initialize' from ap-fail.rb:4:in
new'
from ap-fail.rb:4
shell returned 1
I noticed that 0.3.1 has some errors on Ruby 1.8.4. The current solution is to just stay at 0.2.1 which is fine.
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require': /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap/core_ext/array.rb:17: parse error, unexpected tSTRING_CONTENT (SyntaxError) alias :"original_#{operator.object_id}" :"#{operator}" ^ from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
require'
from /usr/lib/ruby/gems/1.8/gems/awesome_print-0.3.0/lib/ap.rb:6
awesome_print version: 1.0.1
ruby version: 1.9.2-p290
As of 1.0.1 version, Date and DateTime do not print as awesomely as ActiveSupport::TimeWithZone. I think something along the lines should be done:
#object.class is a Date or DateTime
def awesome_date(object)
colorize(object.inspect, :time)
end
Hi, thanks for good package.
I found following code to fail.
#!/usr/bin/env ruby
# following code fail with awesome_print
#require 'awesome_print'
@data = {"1/x" => 1, "2/x" => 2, "3/x" => 3, "x" => 4 }
puts @data.keys.grep(/^(\d+)\//) {$1}
Hi,
It seems there is an error with printing ActiveRecord objects (rails 2.3.5):
Could you give it a look plz?
Thanks!
ArgumentError: wrong number of arguments (1 for 0)
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:42:in red' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:42:in
send'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:42:in colorize' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:53:in
awesome_self'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:26:in format' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:97:in
unnested'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:64:in awesome' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:98:in
awesome_hash'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:286:in indented' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:97:in
awesome_hash'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:96:in map' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:96:in
awesome_hash'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:25:in send' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:25:in
format'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:97:in unnested' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:64:in
awesome'
... 5 levels...
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:52:in awesome_self' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:26:in
format'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:97:in unnested' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:64:in
awesome'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:140:in awesome_object' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:286:in
indented'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:139:in awesome_object' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:130:in
map'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:130:in awesome_object' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:52:in
awesome_self'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/formatter.rb:26:in format' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:97:in
unnested'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/inspector.rb:64:in awesome' from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/core_ext/kernel.rb:10:in
ai'
from /home/konstantin/.rightscale_bundle/right_site/ruby/1.8/bundler/gems/awesome_print-2e75a163874a/lib/awesome_print/core_ext/kernel.rb:15:in `ap'
When using the jnicklas/carrierwave gem in a model, awesome_print tries to append to a nil object resulting in an error:
ruby-1.9.2-p0 > ap Audition.new
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:138:in `awesome_self'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:149:in `awesome'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:86:in `block (2 levels) in awesome_hash'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:210:in `indented'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:85:in `block in awesome_hash'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:79:in `each'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:79:in `inject'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:79:in `awesome_hash'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/mixin/active_record.rb:34:in `awesome_active_record_instance'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/awesome_print.rb:149:in `awesome'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/core_ext/kernel.rb:10:in `ai'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/awesome_print-0.2.1/lib/ap/core_ext/kernel.rb:15:in `ap'
from (irb):8
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in `start'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in `start'
from /Users/kev/.rvm/gems/ruby-1.9.2-p0@global/gems/railties-3.0.0/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I'm not sure if this is being caused by awesome_print or carrierwave. Is there some way I can provide more info to help track the issue down?
Not sure if this is intended, but I just recently updated from an old version and discovered that ap now prints out attr_reader attributes, instance variables and the like. This results in a lot of extra output, that makes things so verbose it's hard to read. Just curious if anyone else is experiencing this and if there's a way to reduce the amount of amount from ap.
When producing HTML (with :html => true or in Rails views), awesome_print encloses each name or value with
...tags, and it produces \n instead of
As a result, the HTML is not "awesome" :) :
rendering is displayed as block, so you have one new line per name, value, etc.
Am I wrong, or we should enclose the whole output by
, instead of each element ?
A few suggestions:
I tried to fork and create a pull request but I couldn't get the repo to work for some reason. Something to do with the calls to Rake inside the gemspec, which didn't play nicely with Bundler. Sorry about that. Anyway, here's the pertinent code. Thanks again for creating such an awesome gem!
# 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 object.is_a?(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[c[1].name] = (c[1].type || "undefined").to_s.underscore.intern rescue c[1].type
hash
end
"class #{object} < #{object.superclass} " << awesome_hash(data)
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
if !object.errors.empty?
data = {:errors => object.errors, :attributes => data}
end
"#{object} #{awesome_hash(data)}"
end
# Format BSON::ObjectId
#------------------------------------------------------------------------------
def awesome_mongoid_bson_id(object)
object.inspect
end
Please read my bug report: http://redmine.ruby-lang.org/issues/4820
I think AP may be causing a crash in ruby. Of course, this is a bug in ruby, but AP seems to be exploiting the bug.
When it crashes it leads me to: /lib/ap/core_ext/class.rb:14: [BUG] Segmentation fault
Hmm, you have labeled that line as EVIL?! Maybe it truly is!
You can try following my steps in the bug report to see if you can make it crash. But it crashes for me, fairly consistently, but not every time. My belief is that there is some interaction with the 'itslog' gem, because if I remove 'itslog' it doesn't crash (limited testing though). But the crash typically points to AP.
Anyone else experiencing a crash?
I'm getting the following test failures with ruby 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]. I suspect these are caused by the hashing order differences in p357 of ruby.
1) AwesomePrint Misc handle array grep when pattern contains / chapacter
Failure/Error: grepped.ai(:plain => true, :multiline => false).should == '[ "1", "2" ]'
expected: "[ \"1\", \"2\" ]"
got: "[ \"2\", \"1\" ]" (using ==)
# ./spec/formats_spec.rb:601
2) Methods arrays obj1.methods.grep(pattern, &block) should pass the matching string within the block
Failure/Error: out.should == [:one, :two]
expected: [:one, :two]
got: [:two, :one] (using ==)
Diff:
@@ -1,2 +1,2 @@
-[:one, :two]
+[:two, :one]
# ./spec/methods_spec.rb:414
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.