Code Monkey home page Code Monkey logo

amazing_print's People

Contributors

0x5424 avatar agrberg avatar basicxman avatar beanieboi avatar clonezone avatar daniel-rikowski avatar dgynn avatar dnnx avatar drewski371-bot avatar duffyjp avatar fujiin avatar georgeu2000 avatar gerrywastaken avatar gudleik avatar harlemsquirrel avatar imajes avatar jclusso avatar kstephens avatar maurogeorge avatar miyucy avatar n-rodriguez avatar nikolajsen avatar nviennot avatar paddor avatar sahglie avatar shyndman avatar stefanwascoding avatar tatsuyafw avatar tobias avatar waldyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

amazing_print's Issues

Use paging with Pry?

When using Pry with Pry.config.pager = true, ap output doesn't get paged. Could this be supported?

Decouple from awesome_print

While we've made some head way already, it would be nice to remove the upstream reference since opening pull requests is defaulting against awesome_print.

We also have revision history that may no longer be relevant.

Enable ruby19_syntax by default

I imagine this is somewhat of a breaking change. But wondering if there's any reason why this wouldn't be enabled by default in 2020.

Project name and first release tag

I see that in forking Awesome Print we also got the tags. Should we tag the first release as v2.0.0 to avoid any confusion or maybe scrub the tags and start over?

While I do like the Awesomer Print name, I'm wondering if it may be a bit too close to it's ancestor and cause confusion. Since we haven't yet made our first release, now is the time to decide this. Naming things is one of the hardest things to do ๐Ÿ™

Possible alternative project names

We should consider any existing gems by searching https://rubygems.org

Preserving ap command and #ai method

  • Amazing Print amazing_print
  • AwePrint aweprint
  • AwePuts aweputs
  • Awesome Puts awesome_puts

Not preserving ap command and #ai method

  • Exploder exploder ep "string.ei
  • GadgetInspector gadgetinspector gp "string".gi
  • SweetPrint sweetprint sp "string".si

ActiveModel::Errors can't modify frozen String

I encountered this error for awesome_active_model_error specifically, haven't seen it in any other formatters yet.

[1] pry(main)> User.first.errors
(pry) output error: #<FrozenError: can't modify frozen String>
~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/amazing_print-1.2.0/lib/amazing_print/ext/active_record.rb:100:in 
~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/amazing_print-1.2.0/lib/amazing_print/formatter.rb:28:in `format'
~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/amazing_print-1.2.0/lib/amazing_print/inspector.rb:124:in `unnested'
~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/amazing_print-1.2.0/lib/amazing_print/inspector.rb:79:in `awesome'
~/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/amazing_print-1.2.0/lib/amazing_print/core_ext/kernel.rb:11:in `ai'
# rest is pry stack

Here's my aprc:

AmazingPrint.defaults = {
  indent: -2,
  index: false,
  color: { args: :whiteish, array: :white, bigdecimal: :blue, class: :purpleish, date: :whiteish, falseclass: :cyanish, integer: :blue, float: :blue, hash: :whiteish, keyword: :cyan, method: :purple, nilclass: :gray, rational: :blue, string: :redish, struct: :purpleish, symbol: :purpleish, time: :whiteish, trueclass: :cyan, variable: :cyanish },
}

I've got a working branch I can open a PR with later today.

Affected (tested) versions

Ruby

  • 2.7.1
  • 2.6.6
  • 2.5.8
    Rails
  • 6.0.3

require "ap" Leads to Conflicts

Hi, first thanks for taking this over.

Amazing and Awesome Print both allow one to say require "ap". In the case of existing Awesome Print code this mostly works. The exception being code that references AwesomePrint, e.g., AwesomePrint.irb!.

Suggestions:

  1. In ap.rb: AwesomePrint = AmazingPrint (assume they're compatible interfaces)
  2. 1 + warnings about this being Amazing Print and AwesomePrint constant will be removed
  3. Unless a goal is backward compatibility (seems like no; from README: ... and should be used in it's place to avoid conflicts) remove ap.rb from future release. Though ruby -rap -e'...' is nice option!
  4. Do nothing!

I think 2 is best. Maybe there are other routes.

undefined method `marshal_dump'

We use below ruby and rails version -

Ruby 2.7.3 Rails 6.1.3.2

While creating a new user it throws the below error -

#<NoMethodError: undefined method `marshal_dump' for #ActiveModel::Errors:0x00007fecf40576f0
Did you mean? marshal_load>

but id didnt use marshal_dump method anywhere in project

Below Create method defined in the controller -

def create

@user = User.new(user_params)

respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end

private

def user_params
  params.require(:user).permit(:name, :email_id, :status)
end

Is there a way to limit or exclude a verbose fields? (i.e. large JSON values)

Hi, thanks for forking, maintaining, and improving this project. I was really happy to see it was being taken care of. ๐Ÿ™

I'm using Rails, and my User model has a large JSON field from redux-token-auth. When I run ap User.first, I get a hugeuser.tokens being a very large JSON field.

  1. Is there any way as I run ap to limit just that field? Or exclude that field?
  2. Is there any way via .aprc to do similar?
  3. Ideally, I wish I could tell amazing_print "if this is a Rails model, consult Model.amazing_print_config, i.e.

Example

class User < ApplicationRecord
  amazing_print_config = {
    # don't print sekrit when using amazing_print
    exclude: [:sekrit],
    # limit printing of tokens to 2 lines when using amazing_print
    limit: { tokens: 2 },
  }

  # ...
end

This problem is exacerbated by the nested printing, i.e. if I do ap Organiation.first, a huge part of the output is the associated User object and it's large user.tokens JSON field.

Readme typo

AmazingPrint is a fork of AwesomePrint which became stale and should be used in it's place to avoid conflicts..

should be:
AmazingPrint is a fork of AwesomePrint which became stale and should be used in its place to avoid conflicts...

NoMethodError: undefined method `inject' for nil:NilClass

Hey ๐Ÿ‘‹

Thank you for maintaining this fork, this is really awesome and i appreciate it!

came here to report a bug in awesome_print but then discovered this fork. So instead i'm reporting it here. There is a bug with the Sequel integration:

class MyModel < Sequel::Model
end

if you are calling MyModel.ai everything works, it shows the database fields. but if you call
Sequel::Model.ai then it breaks with

NoMethodError: undefined method `inject' for nil:NilClass
from /Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/amazing_print-1.0.0/lib/amazing_print/ext/sequel.rb:46:in `awesome_sequel_model_class'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/amazing_print-1.0.0/lib/amazing_print/formatter.rb:26:in `format'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/amazing_print-1.0.0/lib/amazing_print/inspector.rb:122:in `unnested'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/amazing_print-1.0.0/lib/amazing_print/inspector.rb:77:in `awesome'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/amazing_print-1.0.0/lib/amazing_print/core_ext/kernel.rb:9:in `ai'
(pry):1:in `__binding__'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:355:in `eval'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:323:in `handle_line'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/Users/bfritsch/.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:242:in `catch'

Usually you don't call Sequel::Model.ai by itself because it's kinda useless, but it happens when you look at MyModel.ancestors

Thank you so much!
cheers

Can't install gem

Gem is not found on Rubygems

bundle
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Could not find gem 'awesomer_print' in any of the gem sources listed in your Gemfile.
gem install awesomer_print
ERROR:  Could not find a valid gem 'awesomer_print' (>= 0) in any repository
ERROR:  Possible alternatives: awesome_print, awesomeprint, awesome-pry, awesome_engine, awesome_link

print keyword arguments

Is there a way to print the keyword arguments of a method?

class A
  def self.hola(uno: , dos: 'ex')
  end
end
puts (A.methods - Object.methods).ai

this will generate: [0] hola(?, ?) A

I am creating a REPL for Slack on slack-smart-bot gem https://github.com/MarioRuiz/slack-smart-bot and it would be very convenient to print them out like regular method parameters

RSPec cosmetic warnings

Cosmetic, but still they show up in my project when running RSpec with warnings on:

/home/mic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/amazing_print-1.0.0/lib/amazing_print/formatter.rb:29: warning: mismatched indentations at 'end' with 'else' at 27
/home/mic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/amazing_print-1.0.0/lib/amazing_print/formatters/object_formatter.rb:22: warning: mismatched indentations at 'end' with 'else' at 20
/home/mic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/amazing_print-1.0.0/lib/amazing_print/formatters/base_formatter.rb:126: warning: possibly useless use of * in void context
/home/mic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/amazing_print-1.0.0/lib/amazing_print/formatters/struct_formatter.rb:22: warning: mismatched indentations at 'end' with 'else' at 20

Gemfile order matters

If you use this gem and have it placed before Mongoid in your Gemfile, it doesn't work. Is there a way to fix this gem so where it gets placed in the Gemfile doesn't matter?

v1.5 contains a breaking change due to the string convenience methods being removed

Hey folks,

First of all thanks for all the hard work on amazing_print, it's such a handy library for friendlier cli and debuging.

This may be a topic of debate but I believe #91 was a breaking change and should have caused a major version bump under Semantic Versioning guidelines, but it was included in an upgrade from 1.4 to 1.5. The monkey-patching of String may have been gross but it's public API and it's part of the README, and thus by removing it, dependants' implementations could be broken unexpectedly.

I understand it's our responsibility as users of the third-party libraries to ensure new versions of libraries don't break our software but the reality is that many organisations aren't very thorough or often trust in SemVer to make decisions for them. Sadly this did happen in the case of my org! It's a relatively easy fix, but I wanted to share my perspective and I hope it's welcome.

Finally, the README is out of date as it still includes references to the convenience method. I will happily submit a PR to update it.

Again, keep up the good work and thanks.

Argument error with Ruby 2.7.2

Looks like something has changed with Ruby 2.7.2 and interaction with amazing_print. In IRB, when creating a new object and setting it to a variable, we get an ArgumentError. It looks like Ruby 2.7.2/IRB is now returning the output of the object when setting to a variable, which it didn't do in 2.7.1.

Ruby 2.7.2 with amazing_print:

irb(main):004:0> s = String.new
Traceback (most recent call last):
ArgumentError (wrong number of arguments (given 1, expected 0))
irb(main):005:0> String.new
""

Ruby 2.7.2 without amazing_print:

irb(main):001:0> s = String.new
=> ""
irb(main):002:0> String.new
=> ""

Ruby 2.7.1 with amazing_print:

irb(main):004:0> s = String.new
irb(main):005:0> String.new
""

Drop support for Ruby 2.3

Last month support for Ruby 2.4 ended and Rubocop dropped 2.3 support so it's probably time to drop 2.3 support here as well if there are no objections.

This would also mean dropping JRuby 9.1 since that is compatible with Ruby 2.3.x.

Those who desire to use this gem with Ruby 2.3 or JRuby 9.1 could use one of the existing releases.

"can't modify frozen String" error when using Ruby1.9 syntax and left-align

Using the following code (no existing .aprc file):

puts AmazingPrint.version
h = {a: "b", cde: "f"}
puts "plain"
ap(h)
puts "ruby19_syntax"
ap(h, ruby19_syntax: true)
puts "left align"
ap(h, indent: -2)
puts "left aligned ruby19_syntax"
ap(h, ruby19_syntax: true, indent: -2)

you get the following (expected) output using v1.1.0 of AmazingPrint:

1.1.0
plain
{
      :a => "b",
    :cde => "f"
}
ruby19_syntax
{
      a: "b",
    cde: "f"
}
left align
{
  :a   => "b",
  :cde => "f"
}
left aligned ruby19_syntax
{
  a  : "b",
  cde: "f"
}

Starting from version 1.2.0 including to latest git (as of writing), you get a FrozenError on that last test:

1.2.2.pre
plain
{
      :a => "b",
    :cde => "f"
}
ruby19_syntax
{
      a: "b",
    cde: "f"
}
left align
{
  :a   => "b",
  :cde => "f"
}
left aligned ruby19_syntax
Traceback (most recent call last):
	16: from test-ap.rb:14:in `<main>'
	15: from ~ap_checkout/core_ext/kernel.rb:21:in `ap'
	14: from ~ap_checkout/core_ext/kernel.rb:11:in `ai'
	13: from ~ap_checkout/inspector.rb:79:in `awesome'
	12: from ~ap_checkout/inspector.rb:124:in `unnested'
	11: from ~ap_checkout/formatter.rb:28:in `format'
	10: from ~ap_checkout/formatter.rb:81:in `awesome_hash'
	 9: from ~ap_checkout/formatters/hash_formatter.rb:20:in `format'
	 8: from ~ap_checkout/formatters/hash_formatter.rb:37:in `multiline_hash'
	 7: from ~ap_checkout/formatters/hash_formatter.rb:48:in `printable_hash'
	 6: from ~ap_checkout/formatters/hash_formatter.rb:48:in `map!'
	 5: from ~ap_checkout/formatters/hash_formatter.rb:49:in `block in printable_hash'
	 4: from ~ap_checkout/formatters/base_formatter.rb:119:in `indented'
	 3: from ~ap_checkout/inspector.rb:68:in `increase_indentation'
	 2: from ~ap_checkout/indentator.rb:14:in `indent'
	 1: from ~ap_checkout/formatters/hash_formatter.rb:51:in `block (2 levels) in printable_hash'
~ap_checkout/formatters/hash_formatter.rb:89:in `ruby19_syntax': can't modify frozen String: "  a  " (FrozenError)

Default colors only last for one print

This is a bit strange, but I'm noticing that the default colors I have configured work on the first print, but then they revert back to the default colors. I have a black background and the default blue for numbers is hard to see, so I've changed it to cyan:

image

Here I am loading the same object twice, and the first time the numbers are cyan, but the second time they are blue:

image

Stranger still is that when I print out the defaults, the first time the colors are "right" but the defaults are not the ones I set, and the second time the color goes back to blue:

image

Is there a way to not include associated records?

My project users Rails, and has User and Organization models. An Organization can have many Users.

When I run ap Organization.first, I see the organization printed, but I also see nested data for organization.user. Is there a way to tell amazing_print to not recursively print records from associations?

.aprc supports

raw:           false,  # Do not recursively format instance variables.

but that appears to be something different. With it set to false I see recursive values from ActiveRecord relationships printed.

Thanks again for maintaining this library. ๐Ÿ™

"undefined method 'column_names'" for non-AR classes

When calling errors on an instance of a non-AR class, I get undefined method 'column_names':

Pry.config.print = ->(output, value, _) do
  output.puts value.ai
  output.puts
end

class MyClass
  include ActiveModel::Model

  attr_accessor :foo

  validates :foo, presence: true
end

c = MyClass.new
c.valid? # => false
c.errors

(pry) output error: #<NoMethodError: undefined method `column_names' for MyClass:Class>
/Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/amazing_print-1.1.0/lib/amazing_print/ext/active_record.rb:86:in `awesome_active_model_error'
/Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/amazing_print-1.1.0/lib/amazing_print/formatter.rb:26:in `format'
/Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/amazing_print-1.1.0/lib/amazing_print/inspector.rb:122:in `unnested'
/Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/amazing_print-1.1.0/lib/amazing_print/inspector.rb:77:in `awesome'
/Users/manuel/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/amazing_print-1.1.0/lib/amazing_print/core_ext/kernel.rb:9:in `ai'

Disable color for no_tty

This gem has become a standard requirement for development. So much so, that I've even used the built in color methods under the String class.

https://github.com/amazing-print/amazing_print/blob/dbac402f12fee5c2b818b8f555d9f9ac2b035c45/lib/amazing_print/core_ext/string.rb

I do an an issue through. When I'm using a color in a string "this is my string".red I need to disable color when my script runs in no tty.

How do I go about disabling colour after the amazing_print module has already been required in my program?

IRB integration error in OS Ventura

I do not think it has to do with the OS at all but we'll see.
In order to get this working with Ruby 3.0.6 I did this:

  1. Installing as Ruby gem:

    gem install amazing_print
  2. I created a file at ~/.irbrc with this content:

    require "amazing_print"
    AmazingPrint.irb!
    

Then when I enter the IRB console I got this error:

ยฑ irb  
cannot load such file -- amazing_print  
4.0.6 :001 > 

Any thoughts on how to fix it?

Conflict with user configuration file

Seeing these errors,

Could not load '.aprc' from ENV['HOME']: uninitialized constant AwesomePrint
$ cat ~/.aprc
AwesomePrint.defaults = {
  indent: 2,
  plain: true
}

This conflict is a bit problematic.

Additionally, the fact that config file is seemingly constantly reloaded is a bit nuisance. I.e. everytime "ap" is called, it looks like config file is reloaded.

Implement a depth options

(This feature was already requested in awesome_print)

It whould be nice to implement a depth options:

array = [[1,2], [3,4]]

ap(array)
# [
#    [0] [
#        [0] 1,
#        [1] 2
#    ],
#    [1] [
#        [0] 3,
#        [1] 4
#    ]
# ]

ap(array, depth: 1)
# [
#    [0] [1, 2],
#    [1] [3, 4]
# ]

I intended to make a pull request, but the code is pretty complex, I won't say no to be helped.

Problems in use Rack::Test

i switched from awesome_print to this game. When I try debug with pry I have problem with Rack::Test #last_response

[1] pry(#<RSpec::ExampleGroups::Logout::GET::WhenUserLoggedIn>)> last_response
(pry) output error: #<NoMethodError: undefined method `gmtime' for "Thu, 01 Jan 1970 00:00:00 GMT":String>
/usr/local/lib/ruby/2.7.0/cgi/util.rb:188:in `rfc1123_date'
/usr/local/lib/ruby/2.7.0/cgi/cookie.rb:143:in `to_s'
/usr/local/lib/ruby/2.7.0/cgi/cookie.rb:176:in `inspect'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/formatter.rb:52:in `inspect'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/formatter.rb:52:in `inspect'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/formatter.rb:52:in `awesome_self'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/formatter.rb:30:in `format'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/inspector.rb:124:in `unnested'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/inspector.rb:79:in `awesome'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/core_ext/kernel.rb:11:in `ai'
/usr/local/bundle/gems/amazing_print-1.2.2/lib/amazing_print/custom_defaults.rb:47:in `block in pry!'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:302:in `show_result'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:672:in `block in handle_line'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_class.rb:382:in `critical_section'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:671:in `handle_line'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `catch'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `block in eval'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `catch'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `eval'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/repl.rb:77:in `block in repl'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/input_lock.rb:61:in `__with_ownership'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/repl.rb:15:in `start'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/pry_class.rb:191:in `start'
/usr/local/bundle/gems/pry-0.13.1/lib/pry/core_extensions.rb:45:in `pry'
/app/spec/request/logout_spec.rb:32:in `block (4 levels) in <top (required)>'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:262:in `instance_exec'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:262:in `block in run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:508:in `block in with_around_and_singleton_context_hooks'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:465:in `block in with_around_example_hooks'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/hooks.rb:486:in `block in run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/hooks.rb:624:in `run_around_example_hooks_for'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/hooks.rb:486:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:465:in `with_around_example_hooks'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:508:in `with_around_and_singleton_context_hooks'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example.rb:259:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:644:in `block in run_examples'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:640:in `map'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:640:in `run_examples'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:606:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:607:in `block in run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:607:in `map'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:607:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:607:in `block in run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:607:in `map'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/example_group.rb:607:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:121:in `map'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/configuration.rb:2061:in `with_suite_hooks'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:116:in `block in run_specs'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/reporter.rb:74:in `report'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:115:in `run_specs'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:89:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:71:in `run'
/usr/local/bundle/gems/rspec-core-3.9.3/lib/rspec/core/runner.rb:45:in `invoke'
/usr/local/bundle/gems/rspec-core-3.9.3/exe/rspec:4:in `<top (required)>'
/usr/local/bundle/bin/rspec:23:in `load'
/usr/local/bundle/bin/rspec:23:in `<main>'

Any idea why this is happening?

Scrub change log

I think that now we've renamed the project and removed the previous tags, we should begin with a clean change log.

Rails 6.2 will deprecate `marshal_dump`; Breaks awesome_active_model_error

As mentioned in the Rails changelog, they will deprecate Marshal.load as it's too expensive performance-wise:
rails/rails@f93b04a

Effectively, this once again breaks awesome_active_model_error ๐Ÿ˜…
Building rails 6.1.0.alpha locally & latest amazing_print from master I've confirmed the following behavior locally:

[1] pry(main)> Item.first.errors
  Item Load (1.0ms)  SELECT "items".* FROM "items" ORDER BY "items"."id" ASC LIMIT $1  [["LIMIT", 1]]
(pry) output error: #<NoMethodError: undefined method `marshal_dump' for #<ActiveModel::Errors:0x00007fb4da024608>
Did you mean?  marshal_load>
~/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/amazing_print-1fc8b3554284/lib/amazing_print/ext/active_record.rb:87:in `awesome_active_model_error'
~/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/amazing_print-1fc8b3554284/lib/amazing_print/formatter.rb:28:in `format'
~/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/amazing_print-1fc8b3554284/lib/amazing_print/inspector.rb:124:in `unnested'
~/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/amazing_print-1fc8b3554284/lib/amazing_print/inspector.rb:79:in `awesome'
~/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bundler/gems/amazing_print-1fc8b3554284/lib/amazing_print/core_ext/kernel.rb:11:in `ai'
# ...pry stack, etc.

Output with ruby19_syntax: true is not copy pastable

irb(main):033:0> { one: 1, three: 3, four_hundred: 400}
{
  one         : 1,
  three       : 3,
  four_hundred: 400
}

The spaces between one and the : make this invalid Ruby syntax.

I would expect:

{
  one: 1,
  three: 3,
  four_hundred: 400
}

# or even:
{
  one:          1,
  three:        3,
  four_hundred: 400
}

class_name option doesn't seem to do anything

In both Rails 6 console and IRB, (and in the original AwesomePrint gem as well), the class_name option doesn't seem to have any effect.

The class name seems to always be printed as the result of calling to_s on the object, no matter what the class_name option is set to.

o = Object.new
#<Object:0x00007fed5affae48>

ap o
#<Object:0x00007fed5affae48>

ap o, class_name: :to_yaml
#<Object:0x00007fed5affae48>

The reason I'm trying to use this is, I have an ActiveRecord model with a to_s instance method, and want to print out the class/model name when I print it to console or debug log. Example:

class Member < ApplicationRecord
...
    def to_s
        full_name
    end
...
end

ap Member.first

Nathan Fahey {
               :id => "096e9d23-2c66-4e11-8110-50e60e59c05f",
         :zip_code => "10014",
       :first_name => "Nathan",
        :last_name => "Fahey",
...
}

I would like to be able to see the class name, like when I do:

ap Member
class Member < ApplicationRecord {
               :id => :uuid,
         :zip_code => :string,
       :first_name => :string,
        :last_name => :string,
  ...
}

But when I do:

ap Member.first, class_name: :class

or set class_name to any string or symbol, I get the result of Member.first.to_s for the class name.

Also, setting the option, object_id: false does not seem to help.

Raw Mode to avoid double encoding

I have code that uses ap with some default options to print data. At times i'd like to pre-format some data and pass it in. However passing in object.ai(options) results in the string being encoded twice. I'd like to be able to set some sort of "raw" option or to have ai return a wrapped object that should be displayed as is.

JSON

love the gem, but is there a way how to print JSON format ? Meaning hash rocket => replaced by : , keys in quotes, ...) ?

This would be useful when I want to copy paste amazing_printed output to a documentation for a FE developers.

Screenshot?

Hey there,

Would a short screenshot on the main page be possible? I am asking just to look how it compares to awesome_print. I am still using pp most of the time but I'd like to use RGB colours on KDE konsole one day (ap had a few display issues though, which is why I stayed on pp most of the time due to more simplicity).

object_id option not operating as expected

The object_id option is not doing what I expect so either there is a software problem or a wetware problem.

Software Versions:
Amazing ... 1.4.0
Ruby ...... 3.0.1p64
Rails ..... 6.1.3

Running the Rails Console/Irb ....

irb(main):002:0> c = Clinician.first
Clinician Load (1.1ms) SELECT "clinicians".* FROM "clinicians" ORDER BY "clinicians"."id" ASC LIMIT $1 [["LIMIT", 1]]
=>
#<Clinician:0x000000012838e2c0

irb(main):003:0> ap c

I want to get rid of this object ID

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#Clinician:0x000000012838e2c0 {

}
=> nil

irb(main):004:0> ap c, object_id: false

but it is still here ....

#Clinician:0x000000012838e2c0 {

}
=> nil

irb(main):005:0> ap c, object_id: true

but it is still here ...

#Clinician:0x000000012838e2c0 {

}
=> nil

irb(main):006:0> defined? AmazingPrint
=> "constant"

irb(main):007:0> defined? AwesomePrint
=> nil

The same thing happens if I use Awesome.

rails ActiveModel::Attributes support

I have some rails models with custom Postgres jsonb attributes which are serialized/deserialized using the Attributes API. In other words, they are POROs with the following mixins:

  • ActiveModel::Model
  • ActiveModel::Attributes
  • ActiveModel::Serialization

It looks like amazing_print just dumps these by calling inspect on them. What's the right way to add support to amazing print for these types? Add something to amazing_print/lib/amazing_print/ext/? Or modify the ActiveRecord extension? It looks like maybe you could just add another switch case here?

`ruby19_syntax` doesn't work with colorized output

When ruby19_syntax option is set to true alone, it formats a hash using the 1.8 syntax. But when plain is set to true as well, it works as expected. Here's an example:

pry(main)> ap({foo: 3, bar: 4}, { ruby19_syntax: true })
{
  :foo => 3,
  :bar => 4
}
=> nil
pry(main)> ap({foo: 3, bar: 4}, { ruby19_syntax: true, plain: true })
{
  foo: 3,
  bar: 4
}
=> nil

I did a bit of digging and this is what I found. The problem is that symbol? always returns false here:

if options[:ruby19_syntax] && symbol?(key)

That's because the keys of the hash have already been colorized by the call to printable_keys here:

For my first example, data in the above snippet contains the following:

[["\e[0;36m:foo\e[0m", 3], ["\e[0;36m:bar\e[0m", 4]

In the second example, data contains the following:

[[":foo", 3], [":bar", 4]]

The implementation of symbol? checks if the first letter is :, which is false when the keys have been colorized:

def symbol?(key)
key[0] == ':'
end

Support Ruby 3.0 / IRB 1.2.6

IRB v1.2.6 introduced an option to omit / truncate overly long lines of output on assignment. ruby/irb@c5ea79d#diff-ed2717fee59c6f4da595a7fe4ed65be8R749

The implementation details include passing an optional argument [omit] to IRB::Irb#output_value.

# lib/irb.rb

module IRB
  class Irb
  ...
    def output_value(omit = false)
      ...
    end
  ...
  end
end

AmazingPrint redefines output_value without arguments and so raises ArgumentError: wrong number of arguments (given 1, expected 0) when used with IRB >= 1.2.6. (installed with Ruby 3.0)

# lib/amazing_print/custom_defaults.rb

module AmazingPrint
  class << self
  ...
    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
    ...
  end
end

I've done some brief experimenting with adding an unused optional method argument to the method signature of output_value and so far, it appears to fix the compatibility issue without side effects.

Peculiar error hit when doing inspect in rails

Tried to dump out one data structure, which internally contains also references ActionView::Template, and got this

#<ActionView::Template::Error: uninitialized constant Concurrent::Map::DEFAULT_OBJ_ID_STR_WIDTH>
/config/initializers/did_you_mean_patch.rb:10:in `inspect'
/gems/ruby-2.7.2@drt_ui/gems/amazing_print-1.2.2/lib/amazing_print/formatter.rb:52:in `inspect'
/gems/ruby-2.7.2@drt_ui/gems/amazing_print-1.2.2/lib/amazing_print/formatter.rb:52:in `inspect'
    ... skipped 11 ...
/gems/ruby-2.7.2@drt_ui/gems/amazing_print-1.2.2/lib/amazing_print/core_ext/kernel.rb:21:in `ap'```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.