arches / table_print Goto Github PK
View Code? Open in Web Editor NEWThe best data slicer! Watch a 3 minute screencast at http://tableprintgem.com
License: MIT License
The best data slicer! Watch a 3 minute screencast at http://tableprintgem.com
License: MIT License
Hi, your gem looks great!
I need to visualize a lot of data. At the moment I get line wraps which is not workable.
Is it possible to pipe the output to a pager (like less
) somehow ? (this is what Hirb
does by default)
Or maybe how do I specify the screen width so that I don't get line wraps?
That would allow one to scroll data with tmux or similar ?
Thanks!
This gem looks promising for console output, but it would be awesome if it could also output to HTML with a helper method (Rails) for use in views.
I've seen a comment in another PR that you wanted to do this and was wondering if it was in the pipeline and if yes, how far away is this feature?
Thanks!
While trying to print array of hashes which includes UTF-8 symbols
ArgumentError: invalid byte sequence in UTF-8
from /Users/slim/.rvm/gems/ruby-1.9.3-p194/gems/table_print-1.5.1/lib/table_print/formatter.rb:16:in `gsub'
tp LoyaltyCard.limit(10), :except => :retailer_id # no retailer ID column
tp LoyaltyCard.limit(10), :except => :retailer_id, :include => "retailer.name" # shows retailer name AND retailer_id
Given a config with an :include
, eg:
tp.set Store, :include => [{:retailer => {display_method: :retailer_id}}, {:created_at => {width: 19}}, {:updated_at => {width: 19}}]
The first print will use the config and then reset the config. The second print is unconfigured.
Given a config with explicit columns, eg:
tp.set User, :id, :email, :first_name, :last_name, :zipcode, :referral_code, :sign_in_count, :referral_count, :free_referral_count
All prints will use the config.
At display time, multibyte characters are shown as a single column. But when calculating column width, it appears that each byte of the character is counted as a new column. Thus, cells with multibyte characters are displayed too narrowly, breaking the vertical alignment of subsequent columns.
I have this:
tp [[1,2,3],[44,55,66]], :second, :last, object_class: lambda{|ary| ary.first}
which I expect something like:
SECOND | LAST | OBJECT_CLASS |
---|---|---|
2 | 3 | 1 |
55 | 66 | 44 |
but I get a:
NoMethodError: undefined method `first' for 1:Fixnum
from (irb):181:in `block in irb_binding'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:38:in `call'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:38:in `block in populate_row'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:35:in `each'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:35:in `populate_row'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:19:in `block in hash_to_rows'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:18:in `each'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:18:in `hash_to_rows'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print/fingerprinter.rb:9:in `lift'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:41:in `block in table_print'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:40:in `each'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:40:in `table_print'
from /Users/gamov/.rvm/gems/ruby-1.9.3-p545@ector/gems/table_print-1.5.1/lib/table_print.rb:73:in `tp'
If you try without the lambda, you get the improbable following:
>> tp [[1,2,3],[44,55,66]], :first, :second
FIRST | SECOND
---------------|-------
Method Missing | 1
Method Missing | 2
Method Missing | 3
Method Missing | 44
Method Missing | 55
Method Missing | 66
It would be very handy to be able to display arrays of arrays with table_print. Unfortunately, currently, it seems that tp flatten them before displaying the table.
or am I doing something wrong?
example code:
#!/usr/bin/env ruby
require 'table_print'
instances=Array.new
instance=Struct.new(:instance_id, :security_groups)
security_group=Struct.new(:group_name, :group_id)
x=security_group.new('groupa', '1111')
y=security_group.new('groupb', '2222')
c=Array.new
c<<x
c<<y
b=instance.new('a1111', c)
instances<<b
x=security_group.new('groupc', '3333')
y=security_group.new('groupd', '4444')
c=Array.new
c<<x
c<<y
b=instance.new('c3333', c)
instances<<b
l = lambda do |x|
f=""
x.security_groups.each { |a|
f=f+a.group_name+"\n"
}
return f
end
tp instances, :instance_id, :security_groups => l
This prints:
INSTANCE_ID | SECURITY_GROUPS
------------|----------------
a1111 | groupa groupb
c3333 | groupc groupd
But it should print:
INSTANCE_ID | SECURITY_GROUPS
------------|----------------
a1111 | groupa
| groupb
c3333 | groupc
| groupd
Of course the lambda could turn this into an array or similar.
tp target, "foo.bar" # works great
tp target, "foo.bar.xyz" # column appears but isn't populated
In this code in fingerprinter.rb
:
35 handleable_columns(hash).each do |method|
36 display_method = (prefix == "" ? method : "#{prefix}.#{method}")
37 if method.is_a? Proc
38 cell_value = method.call(target)
39 elsif target.is_a? Hash and target.keys.include? method.to_sym
40 cell_value = target[method.to_sym]
41 elsif target.is_a? Hash and target.keys.include? method
42 cell_value = target[method]
43 else
44 cell_value ||= target.send(method)
45 end
46 cells[@column_names_by_display_method[display_method]] = cell_value
47 end
Replace line 43 for:
elsif target.respond_to? method
And you don't get crashes like this, anymore:
/Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:44:in `block in populate_row': undefined method `PrivateIpAddress' for #<Hash:0x007fe92a89d6e8> (NoMethodError)
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:35:in `each'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:35:in `populate_row'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:19:in `block in hash_to_rows'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:18:in `each'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:18:in `hash_to_rows'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:9:in `lift'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:36:in `block in table_print'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:35:in `each'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:35:in `table_print'
from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:66:in `tp'
from ./to-table.rb:14:in `<main>'
only works if the hash keys are strings
irb(main):012:0> tp Retailer.find(43).deals, :retailer => {:display_method => "retailer.name"}, :product_name
SyntaxError: (irb):12: syntax error, unexpected '\n', expecting tASSOC
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
yet this works great:
irb(main):014:0> tp Retailer.find(43).deals, :product_name, :retailer => {:display_method => "retailer.name"}
Right now you can only set one strftime format for your entire process
It would be better if it didn't. Otherwise, every time I start an app or a console that includes a table_print initializer, the first line of output is "No data", which is confusing.
Newlines within the data cause a cell to wrap. Not pretty.
I couldn't figure out if this was possible.
Right now, a method like "first_name" will be printed as FIRST_NAME. Is there any way to override the naming or to format it? I'd much rather have it as "FIRST NAME" than with the underscore.
In older versions of tableprint, one could write rspec stdout expectations such as:
it { expect{ tp table }.to output('No data.').to_stdout }
But with the latest versions of table_print, we are using a separate stdout call (https://github.com/arches/table_print/blob/master/lib/table_print.rb#L73) than the kernel puts
and the rspec output matcher is unable to intercept any of table_print's output making all tests against the library fail.
Is there any way that we can work around this to allow other IOs to be specified as well as maintain compatible so that rspec output matchers can still work?
should print "No data"
> tp.set Activity, :include => "actor.email"
> tp Activity.all
Activity Load (2.5ms) SELECT "activities".* FROM "activities"
NoMethodError: undefined method `#<TablePrint::Column:0x00000007c6f4b0>' for #<Activity:0x00000007cf5218>
from /app/vendor/bundle/ruby/1.9.1/gems/activemodel-3.1.3/lib/active_model/attribute_methods.rb:385:in `method_missing'
from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/attribute_methods.rb:60:in `method_missing'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:39:in `block in populate_row'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:36:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:36:in `populate_row'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:20:in `block in hash_to_rows'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:19:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:19:in `hash_to_rows'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/fingerprinter.rb:12:in `lift'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/table_print.rb:32:in `block in table_print'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/table_print.rb:31:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/table_print.rb:31:in `table_print'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-f439e5dd257d/lib/kernel_extensions.rb:7:in `tp'
from (irb):7
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have a bunch of data with numbers. How would I right-format? Without plugging in lambda. At that rate, I might as well hand-code a table generator.
When deploying my app to heroku, if the table_print gem is in the bundle file in a group that is ignored, the application will fail to launch.
The application launches successfully with table_print if it is in the default group
Gemfile:
source :rubygems
gem 'rails', '3.2.7'
gem 'pg'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'wicked'
gem 'chronic'
gem 'devise', '~> 2.1.0'
gem 'devise_invitable', '~> 1.0.0'
gem 'cancan'
gem 'easy_roles'
gem 'rack-pjax', :git => 'git://github.com/johnsonj/rack-pjax.git'
gem 'meta_search', '>= 1.1.0.pre'
gem 'activeadmin'#, :git => 'git://github.com/gregbell/active_admin.git'
gem 'audited-activerecord', :git => 'git://github.com/johnsonj/audited.git'
gem 'will_paginate', '~> 3.0.0'
group :assets, :production do
gem 'dalli'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'jquery-rails'
gem 'sass-rails', '3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass', '~> 2.0.3'
gem 'jquery-ui-rails'
gem 'font-awesome-rails', :git => 'git://github.com/bokmann/font-awesome-rails.git'
gem 'modernizr-rails'
end
group :production do
gem 'unicorn'
gem 'newrelic_rpm'
gem 'memcachier'
end
group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'capybara'
gem 'guard-rspec'
gem 'rb-inotify', '0.8.8'
gem 'libnotify', '0.5.9'
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
gem 'launchy'
end
group :development do
#gem 'debugger'
gem 'rack-mini-profiler'
gem 'thin'
gem 'rails-dev-boost'
gem 'table_print', :git => "git://github.com/arches/table_print.git", :ref => "5a39d7e05"
end
Deployment output:
jeffrey@ubuntu:~/classbug$ git push heroku
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 311 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.2.0.rc
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/
Updating git://github.com/johnsonj/rack-pjax.git
Updating git://github.com/johnsonj/audited.git
Updating git://github.com/bokmann/font-awesome-rails.git
Updating git://github.com/arches/table_print.git
Fetching gem metadata from http://rubygems.org/......
Fetching gem metadata from http://rubygems.org/..
Using rake (0.9.2.2)
Using i18n (0.6.0)
Using multi_json (1.3.6)
Using activesupport (3.2.7)
Using builder (3.0.0)
Using activemodel (3.2.7)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.3)
Using actionpack (3.2.7)
Using mime-types (1.19)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.4)
Using actionmailer (3.2.7)
Using sass (3.1.20)
Using bourbon (2.1.1)
Using bcrypt-ruby (3.0.1)
Using orm_adapter (0.4.0)
Using rack-ssl (1.3.2)
Using json (1.7.4)
Using rdoc (3.12)
Using thor (0.15.4)
Using railties (3.2.7)
Using warden (1.2.1)
Using devise (2.1.2)
Using fastercsv (1.5.5)
Using formtastic (2.1.1)
Using has_scope (0.5.1)
Using responders (0.9.2)
Using inherited_resources (1.3.1)
Using jquery-rails (2.0.2)
Using kaminari (0.13.0)
Using arel (3.0.2)
Using tzinfo (0.3.33)
Using activerecord (3.2.7)
Using polyamorous (0.5.0)
Using meta_search (1.1.2)
Using activeresource (3.2.7)
Using bundler (1.2.0.rc)
Using rails (3.2.7)
Using activeadmin (0.4.4)
Using audited (3.0.0.rc2) from git://github.com/johnsonj/audited.git (at master)
Using audited-activerecord (3.0.0.rc2) from git://github.com/johnsonj/audited.git (at master)
Using bootstrap-sass (2.0.4.0)
Using cancan (1.6.8)
Using chronic (0.7.0)
Using coffee-script-source (1.3.3)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using coffee-rails (3.2.2)
Using dalli (2.1.0)
Using devise_invitable (1.0.3)
Using easy_roles (1.2.0)
Using font-awesome-rails (0.2.1) from git://github.com/bokmann/font-awesome-rails.git (at master)
Using jquery-ui-rails (1.1.0)
Using kgio (2.7.4)
Using memcachier (0.0.1)
Using modernizr-rails (2.0.6)
Using newrelic_rpm (3.4.1)
Using nokogiri (1.5.5)
Using pg (0.14.0)
Using rack-pjax (0.5.9) from git://github.com/johnsonj/rack-pjax.git (at master)
Using raindrops (0.10.0)
Using sass-rails (3.2.3)
Using uglifier (1.2.6)
Using unicorn (4.3.1)
Using wicked (0.2.0)
Using will_paginate (3.0.3)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
Asset precompilation completed (63.49s)
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
-----> Discovering process types
Procfile declares types -> web
Default types for Ruby/Rails -> console, rake, worker
-----> Compiled slug size is 16.2MB
-----> Launching... done, v98
-----> Deploy hooks scheduled, check output in your logs
http://classbugdev.herokuapp.com deployed to Heroku
To [email protected]:classbugdev.git
0c42909..b9e24e7 master -> master
Heroku Log:
2012-08-01T21:57:24+00:00 heroku[api]: Release v98 created by [email protected]
2012-08-01T21:57:24+00:00 heroku[api]: Deploy b9e24e7 by [email protected]
2012-08-01T21:57:24+00:00 heroku[web.1]: State changed from up to starting
2012-08-01T21:57:25+00:00 heroku[slugc]: Slug compilation finished
2012-08-01T21:57:27+00:00 heroku[web.1]: Starting process with command `bundle exec unicorn -p 3543 -c ./config/unicorn.rb`
2012-08-01T21:57:27+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2012-08-01T21:57:28+00:00 app[web.1]: I, [2012-08-01T21:57:28.226538 #2] INFO -- : reaped #<Process::Status: pid 27 exit 0> worker=0
2012-08-01T21:57:28+00:00 app[web.1]: I, [2012-08-01T21:57:28.226914 #2] INFO -- : reaped #<Process::Status: pid 30 exit 0> worker=1
2012-08-01T21:57:28+00:00 app[web.1]: I, [2012-08-01T21:57:28.341005 #2] INFO -- : master complete
2012-08-01T21:57:28+00:00 app[web.1]: I, [2012-08-01T21:57:28.339153 #2] INFO -- : reaped #<Process::Status: pid 32 exit 0> worker=2
2012-08-01T21:57:29+00:00 heroku[web.1]: Process exited with status 0
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:799:in `load_spec_files'
2012-08-01T21:57:29+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:801:in `rescue in load_spec_files': git://github.com/arches/table_print.git (at 5a39d7e) is not checked out. Please run `bundle install` (Bundler::GitError)
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:381:in `local_specs'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:774:in `specs'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:193:in `block (2 levels) in index'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:188:in `each'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:188:in `block in index'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/index.rb:9:in `build'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:184:in `index'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:116:in `specs'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:158:in `specs_for'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/environment.rb:23:in `requested_specs'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:147:in `requested_specs'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler.rb:116:in `setup'
2012-08-01T21:57:29+00:00 app[web.1]: from <internal:lib/rubygems/custom_require>:29:in `require'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/runtime.rb:11:in `setup'
2012-08-01T21:57:29+00:00 app[web.1]: from <internal:lib/rubygems/custom_require>:29:in `require'
2012-08-01T21:57:29+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/setup.rb:17:in `<top (required)>'
2012-08-01T21:57:31+00:00 heroku[web.1]: Process exited with status 1
2012-08-01T21:57:31+00:00 heroku[web.1]: State changed from starting to crashed
2012-08-01T21:57:31+00:00 heroku[web.1]: State changed from crashed to starting
2012-08-01T21:57:34+00:00 heroku[web.1]: Starting process with command `bundle exec unicorn -p 46361 -c ./config/unicorn.rb`
2012-08-01T21:57:36+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:801:in `rescue in load_spec_files': git://github.com/arches/table_print.git (at 5a39d7e) is not checked out. Please run `bundle install` (Bundler::GitError)
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:799:in `load_spec_files'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:381:in `local_specs'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/source.rb:774:in `specs'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:193:in `block (2 levels) in index'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:188:in `block in index'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:188:in `each'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/index.rb:9:in `build'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:158:in `specs_for'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:184:in `index'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:116:in `specs'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/definition.rb:147:in `requested_specs'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/environment.rb:23:in `requested_specs'
2012-08-01T21:57:36+00:00 app[web.1]: from <internal:lib/rubygems/custom_require>:29:in `require'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler.rb:116:in `setup'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/runtime.rb:11:in `setup'
2012-08-01T21:57:36+00:00 app[web.1]: from <internal:lib/rubygems/custom_require>:29:in `require'
2012-08-01T21:57:36+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc/lib/bundler/setup.rb:17:in `<top (required)>'
2012-08-01T21:57:37+00:00 heroku[web.1]: Process exited with status 1
2012-08-01T21:57:37+00:00 heroku[web.1]: State changed from starting to crashed
2012-08-01T21:57:38+00:00 heroku[router]: Error H10 (App crashed) -> GET classbugdev.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
If I use the width option like this
tp $scen, {"features.name" => {display_name: "Features", width: 30}},
{"features.scenarios.name" => {display_name: "Scenarios", :width => 50}},
{"features.scenarios.time" => {display_name: "Time", width: 10}},
{"features.scenarios.steps" => {display_name: "Steps", width: 10}},
{"features.scenarios.tps" => {display_name: "TPS", width: 10}}
It does absolutely nothing unless the width is already less than whatever width it's already using. In other words it shows this for everything past 19, and only if I lower the width below that amount will it change the width.
FEATURES | SCENARIOS | TIME | STEPS | TPS
-------------------|---------------------------|--------|-------|-----------
Find Account Tests | No search results in erro | 16.392 | 6 | 2.73199...
| Field Search, Examples (# | 3.869 | 10 | 0.3869
| Field Search, Examples (# | 3.637 | 10 | 0.3637
| Field Search, Examples (# | 3.647 | 10 | 0.36469...
| Field Search, Examples (# | 3.537 | 10 | 0.3537
| Field Search, Examples (# | 3.647 | 10 | 0.36469...
| Field Search, Examples (# | 3.701 | 10 | 0.3701
| Field Search, Examples (# | 3.608 | 10 | 0.3608
On the same topic I cannot figure out how to make things group correctly. I'm not using active record and there are no examples of how to use this with a hash even though the Readme says it supports it. I've created custom classes and I've gotten closer, but I still don't understand at all how to use this gem without ActiveRecord.
TATFT
It would be nice to have the option to print row numbers for each row in a table.
table_print adds cattr_reader, cattr_writer, and cattr_accessor methods to Class. potentially breaks devise, and is just all around a bad idea.
Any columns that involve a secondary object take 5, 10, even 20+ seconds to complete. Something like tp User.limit(30), :id, :email, "orders.account_number"
should return in under 2 seconds.
TablePrint::Config.max_width = 30
> tp ... {title: {width: 20}} # title column is 20 wide
> tp ... {title: {width: 40}} # title column is 30 wide
Currently column order can be inconsistent (especially on 1.8.7, I hear)
> tp Order.order("id desc").where('referral_code is not null'), :id, :number, :referred_by_id, :referral_code, :created_at, :user => {:display_method => Proc.new{|r| User.find_by_referral_code(r.referral_code)}}
Order Load (8.5ms) SELECT "orders".* FROM "orders" WHERE (referral_code is not null) ORDER BY id desc
User Load (26.5ms) SELECT "users".* FROM "users" WHERE "users"."referral_code" = '1AMY6H' LIMIT 1
TypeError: #<Proc:0x000000093b7f78@(irb):12> is not a symbol
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:39:in `block in populate_row'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:36:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:36:in `populate_row'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:20:in `block in hash_to_rows'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:19:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:19:in `hash_to_rows'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/fingerprinter.rb:12:in `lift'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/table_print.rb:33:in `block in table_print'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/table_print.rb:32:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/table_print.rb:32:in `table_print'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/kernel_extensions.rb:7:in `tp'
from (irb):12
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
This is more of a feature request. I looked through the config and couldn't find an option like this. Apologies if I missed it.
An option to have results such that each column of each row is on a separate line? (In postgres its call expanded table formatting - \x)
EG:
id | email
----+----------------------
1 | [email protected]
2 | [email protected]
would become:
-[ RECORD 1 ]---------------
id | 1
email | [email protected]
-[ RECORD 2 ]---------------
id | 2
email | [email protected]
Great gem! I've been using it today and its awesome.
It would probably be good for you to update the README to suggest installing a later (or just the latest) version of tableprint instead of:
gem "table_print", "~> 1.0.0"
If people follow those directions, they would only get version 1.0.1.
One of the orders doesn't have any discount codes. Thought this had been taken care of but apparently not.
irb(main):036:0> tp User.chris.orders, :id, :number, {:price => {display_method: :total_price_in_cents}}, {:payment => {display_method: :payment_total_in_cents}}, :emailed, :status, {:quantity => {:display_method => "line_items.quantity"}}, {:youtech_id => {:display_method => "line_items.redeemables.youtech_id"}}, "discount_codes.discount_type"
User Load (25.9ms) SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
Order Load (4.3ms) SELECT "orders".* FROM "orders" WHERE "orders"."user_id" = 1057529309
LineItem Load (1.9ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."order_id" = 1069293442
Redeemable Load (4.6ms) SELECT "redeemables".* FROM "redeemables" WHERE "redeemables"."line_item_id" = 22223
DiscountCode Load (6.6ms) SELECT "discount_codes".* FROM "discount_codes" WHERE "discount_codes"."order_id" = 1069293442
LineItem Load (1.7ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."order_id" = 1069293441
Redeemable Load (5.9ms) SELECT "redeemables".* FROM "redeemables" WHERE "redeemables"."line_item_id" = 22222
DiscountCode Load (5.5ms) SELECT "discount_codes".* FROM "discount_codes" WHERE "discount_codes"."order_id" = 1069293441
LineItem Load (4.7ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."order_id" = 1069293440
Redeemable Load (5.0ms) SELECT "redeemables".* FROM "redeemables" WHERE "redeemables"."line_item_id" = 22221
DiscountCode Load (4.4ms) SELECT "discount_codes".* FROM "discount_codes" WHERE "discount_codes"."order_id" = 1069293440
NoMethodError: undefined method `cells' for nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/row_group.rb:154:in `block in collapse!'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/row_group.rb:152:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/row_group.rb:152:in `collapse!'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/row_group.rb:109:in `each'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/row_group.rb:109:in `collapse!'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/table_print.rb:36:in `table_print'
from /app/vendor/bundle/ruby/1.9.1/bundler/gems/table_print-078f10ada34a/lib/kernel_extensions.rb:7:in `tp'
from (irb):36
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Right now table_print uses puts
to show data on the screen. That's great unless you want to further work with the output. Make it possible to either pass in an IO object that table_print will use, or somehow return a new IO object for further use.
eg, tp.set :max_width, 20
Would be neat if table_print was on code climate, it's free for oss.
This is what I see by default :( -
tp User.all
INCLUDE_ROOT_IN_JSON? | _INDEX | NESTED_ATTRIBUTES | NESTED_ATTRIBUTES? | READONLY_ATTRIBUTES | READONLY_ATTRIBUTES? | ALIASED_FIELDS | ALIASED_FIELDS? | LOCALIZED_FIELDS | LOCALIZED_FIELDS? | FIELDS | FIELDS? | PRE_PROCESSED_DEFAULTS | PRE_PROCESSED_DEFAULTS? | POST_PROCESSED_DEFAULTS | POST_PROCESSED_DEFAULTS? | ___ID_DEFAULT__ | ID | INDEX_SPECIFICATIONS | CASCADES | CASCADES? | CYCLIC | CYCLIC? | EMBEDDED_RELATIONS | EMBEDDED_RELATIONS? | RELATIONS | RELATIONS? | POLYMORPHIC | POLYMORPHIC? | DEFAULT_SCOPING | DEFAULT_SCOPING? | _DECLARED_SCOPES | _DECLARED_SCOPES? | STORAGE_OPTIONS | SHARD_KEY_FIELDS | _PARENT | VALIDATION_CONTEXT | _VALIDATE_CALLBACKS | _VALIDATE_CALLBACKS? | _VALIDATORS | _VALIDATORS? | _VALIDATION_CALLBACKS | _VALIDATION_CALLBACKS? | _BUILD_CALLBACKS | _BUILD_CALLBACKS? | _FIND_CALLBACKS | _FIND_CALLBACKS? | _INITIALIZE_CALLBACKS | _INITIALIZE_CALLBACKS? | _TOUCH_CALLBACKS | _TOUCH_CALLBACKS? | _CREATE_CALLBACKS | _CREATE_CALLBACKS? | _DESTROY_CALLBACKS | _DESTROY_CALLBACKS? | _SAVE_CALLBACKS | _SAVE_CALLBACKS? | _UPDATE_CALLBACKS | _UPDATE_CALLBACKS? | _UPSERT_CALLBACKS | _UPSERT_CALLBACKS? | BEFORE_CALLBACK_HALTED | PASSWORD | PASSWORD_CONFIRMATION | _CALLBACK_BEFORE_5_OBJECT | _CALLBACK_BEFORE_5 | _CALLBACK_BEFORE_7_OBJECT | _CALLBACK_BEFORE_7 | _CALLBACK_BEFORE_8_OBJECT | _CALLBACK_BEFORE_8 | _CALLBACK_BEFORE_10 | _CALLBACK_BEFORE_11_OBJECT | _CALLBACK_BEFORE_11 | AUDIT_SESSIONS? | HAS_AUDIT_SESSIONS? | AUDIT_SESSION_IDS | _CALLBACK_BEFORE_12_OBJECT | _CALLBACK_BEFORE_12 | _CALLBACK_BEFORE_13 | _CALLBACK_BEFORE_14 | _CALLBACK_BEFORE_15_OBJECT | _CALLBACK_BEFORE_15 | _CALLBACK_BEFORE_16_OBJECT | _CALLBACK_BEFORE_16 | _CALLBACK_BEFORE_17_OBJECT | _CALLBACK_BEFORE_17 | _CALLBACK_BEFORE_18_OBJECT | _CALLBACK_BEFORE_18 | _CALLBACK_BEFORE_19_OBJECT | _CALLBACK_BEFORE_19 | TRACK | ALLOWED_EVENT_ZONES? | HAS_ALLOWED_EVENT_ZONES? | _CALLBACK_BEFORE_20_OBJECT | _CALLBACK_BEFORE_20 | ALLOWED_LIVE_ZONES? | HAS_ALLOWED_LIVE_ZONES? | _CALLBACK_BEFORE_21_OBJECT | _CALLBACK_BEFORE_21 | NAME | REGENERATE_TOKEN_IF_NEEDED
----------------------|--------|-------------------|--------------------|-------------------------|----------------------|----------------|-----------------|------------------|-------------------|--------------------------------|---------|------------------------|-------------------------|-------------------------|--------------------------|--------------------------|--------------------------|----------------------|----------------|-----------|--------|---------|--------------------|---------------------|--------------------------------|------------|-------------|--------------|--------------------------------|------------------|------------------|-------------------|--------------------------------|------------------|---------|--------------------|--------------------------------|----------------------|--------------------------------|--------------|-----------------------|------------------------|------------------|-------------------|-----------------|------------------|-----------------------|------------------------|------------------|-------------------|--------------------------------|--------------------|--------------------|---------------------|--------------------------------|------------------|--------------------------------|--------------------|-------------------|--------------------|------------------------|----------|-----------------------|--------------------------------|--------------------|--------------------------------|--------------------|--------------------------------|-----------------------|---------------------|--------------------------------|-----------------------|-----------------|---------------------|--------------------------|--------------------------------|---------------------|---------------------|---------------------|--------------------------------|---------------------|--------------------------------|---------------------|--------------------------------|---------------------|--------------------------------|---------------------|--------------------------------|---------------------|-------|----------------------|--------------------------|--------------------------------|---------------------|---------------------|-------------------------|--------------------------------|---------------------|---------------|---------------------------
false | | {} | true | #<Set:0x007fb8568ef290> | true | {"id"=>"_id"} | true | {} | true | {"_id"=>#<Mongoid::Fields::... | true | ["_id", "active", "... | true | ["admin", "staff"] | true | 527eac59526f6d1160000000 | 527a718b526f6d4dee000000 | [] | ["audit_ses... | true | | false | {} | true | {"audit_sessions"=>#<Mongoi... | true | | false | #<Proc:0x007fb856b6c860@/us... | true | {} | true | {:collection=>:users, :sess... | [] | | | [#<ActiveSupport::Callbacks... | true | {:password=>[#<ActiveModel:... | true | [] | true | [] | true | [] | true | [] | true | [] | true | [#<ActiveSupport::Callbacks... | true | [] | true | [#<ActiveSupport::Callbacks... | true | [#<ActiveSupport::Callbacks... | true | [] | true | | | | #<ActiveModel::Validations:... | [:password] | #<Mongoid::Validatable::Pre... | [:password] | #<Mongoid::Validatable::Pre... | [:password_confirm... | | #<Mongoid::Validatable::Pre... | [:password_confirm... | true | true | [BSON::ObjectId('527c... | #<Mongoid::Validatable::Ass... | [:audit_sessions] | | [:active, :passw... | #<ActiveModel::Validations:... | [:time_zone] | #<Mongoid::Validatable::Pre... | [:email] | #<EmailValidator:0x007fb856... | [:email] | #<Mongoid::Validatable::Uni... | [:email] | #<Mongoid::Validatable::Pre... | [:first_name, :l... | true | false | false | #<Mongoid::Validatable::Ass... | [:allowed_event_... | false | false | #<Mongoid::Validatable::Ass... | [:allowed_live_z... | Roman Gaufman | [:active, :password_dig...
Customize colunn headers is a bit difficult for this simple a requirement. Also contains a bug.
For example when I do
tp systems, :system => {:display_method => :name}, :epic => {:display_method => :xyz}
The second column will never be displayed. It is also not called it seems. I can specifiy any symbol, existing method or not. Only system column is displayed.
Heroku console output:
>> tp Delayed::Job.last
NoMethodError: undefined method `first' for #<Delayed::Backend::ActiveRecord::Job:0x7fd57e69b878>
/app/.bundle/gems/ruby/1.8/gems/activemodel-3.0.9/lib/active_model/attribute_methods.rb:392:in `method_missing'
/app/.bundle/gems/ruby/1.8/gems/activerecord-3.0.9/lib/active_record/attribute_methods.rb:46:in `method_missing'
/app/.bundle/gems/ruby/1.8/gems/table_print-0.2.1/lib/table_print.rb:46:in `tp'
/app/.bundle/gems/ruby/1.8/gems/table_print-0.2.1/lib/table_print.rb:341:in `tp'
Need to strip newlines from cell contents to prevent unexpected wrapping
fixed a huge bug with this in 1.3.3 but didn't write a spec for it.
When a column is truncated by the config'd max_width, the separator isn't similarly shortened.
I saw your project on RubyFlow and noticed it was very similar to Hirb. If you didn't know about that project, you may want to check it out for inspiration or collaboration.
Would be awesome to be able to track a table in real time, maybe print headers every 30 rows or whatever
Class based config is cool but I never want to use it because I'm afraid I'll forget I set it up and then I'll be presented with a picture of the world that I think is complete but actually isn't. Some possible ways to address this:
tp.for CreditCard
for more info."tp.for User
tp.set :use_class_config, false
Maybe you have a bunch of json that you want to see in columns
For example when I do
tp systems, :system => {:display_method => :name}, :epic => {:display_method => :xyz}The second column will never be displayed. It is also not called it seems. I can specifiy any symbol, existing method or not. Only system column is displayed.
-@ostraaten
Make it possible to specify two columns within a single hash, instead of forcing you to add curly braces to turn each column into its own hash
Sometimes I get an error where something can't be found. Vague, yes. Just making a note here so I don't forget to try to repro.
If I use more that one lambda column, only the first one is included.
This command:
tp User.all, :id, :email, :sign_in_count, :email_weekly_report, :email_news, :data_files_count => lambda{|u| u.app_data_files.count}, :email_count => lambda{|u| u.emails.count}, :records_count => lambda{|u| u.records.count}
Gives this output:
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.