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

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

Open
aguynamedben opened this issue Dec 17, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@aguynamedben
Copy link

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.

@HarlemSquirrel
Copy link
Member

Hmm, I don't think we have a build in way to do this today. @paddor correct me if I'm wrong.

This does sound like a useful improvement we should add.

@HarlemSquirrel HarlemSquirrel added the enhancement New feature or request label Jan 24, 2021
@paddor
Copy link
Contributor

paddor commented Jan 25, 2021

@aguynamedben

  1. You could maybe dup the record, remove that JSON field, and then log it.
  2. I thought setting limit applies to all Arrays/Hashes, so setting in .aprc might work.
  3. I agree, this sounds like a great feature for AR users.

@inkstak
Copy link

inkstak commented Mar 2, 2021

This would be really helpful on models with geometry attributes that can take hundreds of lines.

@inkstak
Copy link

inkstak commented Mar 2, 2021

ActiveRecord offers an easy way to limit output of long attributes:

class ApplicationRecord < ActiveRecord::Base
  def format_for_inspect(name, value)
    value = value.to_s.truncate(60).inspect if value.is_a?(RGeo::Feature::Instance)
    super(name, value)
  end
end

@gilesbowkett
Copy link

I haven't found format_for_inspect to be useful in my case, probably because it's not a string type but rather a Postgres array. so far my coping strategy is tacking a select_without(:huge_array_field) onto the query. I'll probably turn that into a scope with a name like readable (or even merciful).

the strategy has a limitation which is probably obvious, though — sometimes I need to work with the huge array field — so I would love to have this feature also.

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

No branches or pull requests

5 participants