hirb
hirb copied to clipboard
Support nil rows in table
Suppose that I am doing the following:
User.where(...).map {|u| u.projects.last}
But not all users are having projects, only some of them. In this case what I am gonna see is:
Hirb Error: undefined method `id' for nil:NilClass
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:10:in `block (2 levels) in render'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:10:in `each'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:10:in `inject'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:10:in `block in render'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:9:in `each'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:9:in `inject'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/object_table.rb:9:in `render'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/helpers/auto_table.rb:22:in `render'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/formatter.rb:73:in `_format_output'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/formatter.rb:56:in `format_output'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/view.rb:205:in `render_output'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/view.rb:123:in `view_output'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/view.rb:201:in `view_or_page_output'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/hirb-0.7.3/lib/hirb/view.rb:187:in `output_value'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:490:in `block (2 levels) in eval_input'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:623:in `signal_status'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:486:in `block in eval_input'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:245:in `block (2 levels) in each_top_level_statement'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:231:in `loop'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:231:in `block in each_top_level_statement'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:230:in `catch'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb/ruby-lex.rb:230:in `each_top_level_statement'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:485:in `eval_input'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:395:in `block in start'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:394:in `catch'
/Users/bogdan/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/irb.rb:394:in `start'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/railties-4.1.10/lib/rails/commands/console.rb:90:in `start'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/railties-4.1.10/lib/rails/commands/console.rb:9:in `start'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:69:in `console'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/railties-4.1.10/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
/Users/bogdan/.rvm/gems/ruby-2.2.2@talkable/gems/railties-4.1.10/lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:8:in `require'
bin/rails:8:in `<main>'
if the first user in result has projects and inspect
output otherwise.
This is tricky and very confusing.
It would be cooler if hirb would realise that some objects in result set are nil and some are not, and represent nil rows with some clear ASCII graphics instead.
Thanks for reporting your issue! This is one of my 1 active issues. Use that link to check how soon your issue will be answered. Don't forget to check your issue against this project's CONTRIBUTING.md. Cheers.
I'm open to a pull request depending on what the specific ASCII graphic is. Personally I don't have a need for this use case. I would just append .compact
to any troublesome result
Append .compact
doesn't always tell you a story. Especially when you are viewing a small set of records and want to know corresponding project
for each. .compact
will remove relations: you would know that only m of n users have projects but you don't know which ones from the initial list.
Understood. I'm open to an explorative pull request
It appears that all items in an array are treated as the same type.
When I do
2.2.2 :010 > [Katello::Repository.first, Katello::ContentViewPuppetEnvironment.first]
I am seeing
Hirb Error: undefined method `cp_label' for #<Katello::ContentViewPuppetEnvironment:0x000000077a7ab8>
UPDATE: I am using hirb-0.7.3