Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 'depth' in options #343

Open
maciejpk opened this issue Jul 12, 2018 · 1 comment
Open

[Feature] 'depth' in options #343

maciejpk opened this issue Jul 12, 2018 · 1 comment

Comments

@maciejpk
Copy link

This is actually a feature request that shouldn't be hard to implement.
What I actually would like to have, is a depth of "awesome printing", so when for example I have an array like:

arr = [
  [1,2,3],
  [4,5,6],
  [7,8,9]
]

then for depth == 2 it would print it the usual way, which would be ap arr, but if the depth == 1 then it would be displayed like in the above manner.

Reason for this feature? Pluck command. Let's take an ActiveRecord and do something like this
ap User.where(...).pluck(:id, :created_at, :updated_at)
It would be printed in an ugly way, which would be something alike

[
    [ 0] [
        [0] 6,
        [1] Fri, 22 Jun 2018 10:31:53 UTC +00:00,
        [2] Fri, 22 Jun 2018 10:31:53 UTC +00:00
    ],
    [ 1] [
        [0] 7,
        [1] Tue, 26 Jun 2018 09:00:50 UTC +00:00,
        [2] Tue, 26 Jun 2018 09:00:50 UTC +00:00
    ],
    [ 2] [
        [0] 8,
        [1] Tue, 26 Jun 2018 09:01:09 UTC +00:00,
        [2] Tue, 26 Jun 2018 09:01:09 UTC +00:00
    ],
    [ 3] [
        [0] 10,
        [1] Wed, 27 Jun 2018 07:28:20 UTC +00:00,
        [2] Wed, 27 Jun 2018 07:28:20 UTC +00:00
    ]
]

when instead I would like it to show each record as a row, so that would look something like this

[
    [ 0] [6, Fri, 22 Jun 2018 10:31:53 UTC +00:00, Fri, 22 Jun 2018 10:31:53 UTC +00:00],
    [ 1] [7, Tue, 26 Jun 2018 09:00:50 UTC +00:00, Tue, 26 Jun 2018 09:00:50 UTC +00:00],
    [ 2] [8, Tue, 26 Jun 2018 09:01:09 UTC +00:00, Tue, 26 Jun 2018 09:01:09 UTC +00:00],
    [ 3] [10, Wed, 27 Jun 2018 07:28:20 UTC +00:00, Wed, 27 Jun 2018 07:28:20 UTC +00:00]
]
@maciejpk maciejpk changed the title 'depth' in options [Feature] 'depth' in options Jul 12, 2018
@bmon
Copy link

bmon commented Sep 6, 2018

I've also found myself wanting this, the example above can be patched in (i.e in ~/.pryrc) like so:

require "awesome_print"
module AwesomePrint
  module Formatters
    class ArrayFormatter
      alias old_gen generate_printable_array
      def generate_printable_array
        options[:multiline] = false
        old_gen
      end
    end
  end
end
AwesomePrint.pry!

Doesn't support depth, and if you want to start printing out complex objects it will wrap and look very ugly, but for a quick hack it does the trick pretty well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants